clauncher/launcher.sh

46 lines
966 B
Bash
Executable File

#!/usr/bin/env bash
cacheDir=${XDG_CACHE_HOME:-"$HOME/.cache"}
configDir=${XDG_CONFIG_HOME:-"$HOME/.config"}/clauncher
cache="$cacheDir/launcher_opts"
historyFile="$cacheDir/launcher_opts_history"
if ! [ -f "$cache" ]; 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 > "$cache"
fi
gawk -v histfile=$historyFile '
BEGIN {
while( (getline < histfile) > 0 ) {
sub("^[0-9]+\t","")
print
x[$0]=1
}
} !x[$0]++ ' "$cache" \
| fzf -e --tiebreak=index \
| gawk -v histfile=$historyFile '
BEGIN {
FS=OFS="\t"
while ( (getline < histfile) > 0 ) {
count=$1
sub("^[0-9]+\t","")
fname=$0
history[fname]=count
}
close(histfile)
}
{
history[$0]++
print
}
END {
if(!NR) exit
for (f in history)
print history[f],f | "sort -t '\t' -k1rn >" histfile
}
' \
| xargs -I {} open -a "{}"