Refactor and delete clauncher-update
This commit is contained in:
parent
798a43bac3
commit
498a4ddca1
36
clauncher
36
clauncher
|
@ -2,15 +2,17 @@
|
|||
|
||||
cacheDir=${XDG_CACHE_HOME:-"$HOME/.cache"}
|
||||
configDir=${XDG_CONFIG_HOME:-"$HOME/.config"}/clauncher
|
||||
|
||||
cacheFile="$cacheDir/launcher_opts"
|
||||
historyFile="$cacheDir/launcher_opts_history"
|
||||
|
||||
if ! [[ -f "$cacheFile" ]] || [[ "$1" == "update" ]]; then
|
||||
update_cache() {
|
||||
if ! [[ -f "$cacheFile" ]] || [[ "$1" == "update" ]]; then
|
||||
"$configDir"/capture.zsh 'open -a' | sed -e 's/.*-a//' -e "s/\\\//g" -e "s/\r//g" | grep -v -f "$configDir"/.open_ignore | (cat "$configDir"/.open_add; cat -) | sort -u > "$cacheFile"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
gawk -v histfile=$historyFile '
|
||||
run_launcher() {
|
||||
gawk -v histfile=$historyFile '
|
||||
BEGIN {
|
||||
while( (getline < histfile) > 0 ) {
|
||||
sub("^[0-9]+\t","")
|
||||
|
@ -43,3 +45,29 @@ gawk -v histfile=$historyFile '
|
|||
}
|
||||
' \
|
||||
| xargs -I {} open -a "{}"
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
usage: ${0##*/} [command]
|
||||
update - Update program list
|
||||
help - Display this help message
|
||||
EOF
|
||||
}
|
||||
|
||||
runScript() {
|
||||
if [ "$#" -eq 0 ]; then
|
||||
update_cache
|
||||
run_launcher
|
||||
elif [ "$1" == "update" ]; then
|
||||
update_cache
|
||||
elif [ "$1" == "help" ]; then
|
||||
usage
|
||||
exit 0
|
||||
else
|
||||
echo "Invalid command. Use 'help' to see available commands."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
runScript "$@"
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cacheDir=${XDG_CACHE_HOME:-"$HOME/.cache"}
|
||||
configDir=${XDG_CONFIG_HOME:-"$HOME/.config"}/clauncher
|
||||
|
||||
cache="$cacheDir/launcher_opts"
|
||||
|
||||
"$configDir"/capture.zsh 'open -a' | sed -e 's/.*-a//' -e "s/\\\//g" -e "s/\r//g" | grep -v -f "$configDir"/.open_ignore | (cat "$configDir"/.open_add; cat -) | sort -u > "$cache"
|
||||
|
Loading…
Reference in New Issue