Refactor and delete clauncher-update
This commit is contained in:
parent
798a43bac3
commit
498a4ddca1
30
clauncher
30
clauncher
|
@ -2,14 +2,16 @@
|
||||||
|
|
||||||
cacheDir=${XDG_CACHE_HOME:-"$HOME/.cache"}
|
cacheDir=${XDG_CACHE_HOME:-"$HOME/.cache"}
|
||||||
configDir=${XDG_CONFIG_HOME:-"$HOME/.config"}/clauncher
|
configDir=${XDG_CONFIG_HOME:-"$HOME/.config"}/clauncher
|
||||||
|
|
||||||
cacheFile="$cacheDir/launcher_opts"
|
cacheFile="$cacheDir/launcher_opts"
|
||||||
historyFile="$cacheDir/launcher_opts_history"
|
historyFile="$cacheDir/launcher_opts_history"
|
||||||
|
|
||||||
|
update_cache() {
|
||||||
if ! [[ -f "$cacheFile" ]] || [[ "$1" == "update" ]]; then
|
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"
|
"$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
|
||||||
|
}
|
||||||
|
|
||||||
|
run_launcher() {
|
||||||
gawk -v histfile=$historyFile '
|
gawk -v histfile=$historyFile '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
while( (getline < histfile) > 0 ) {
|
while( (getline < histfile) > 0 ) {
|
||||||
|
@ -43,3 +45,29 @@ gawk -v histfile=$historyFile '
|
||||||
}
|
}
|
||||||
' \
|
' \
|
||||||
| xargs -I {} open -a "{}"
|
| 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