shownotes-w3m-rice/fzf_speed/_applauncher,--.start.programs.in.new.window

28 lines
936 B
Plaintext
Raw Normal View History

2021-07-03 23:23:15 +00:00
#!/usr/bin/env sh
TMPFILE="/tmp/fzfspeed_applauncher.txt"
FZF_ARG() {
fzf -e -i -m --delimiter '/' --with-nth -1 --prompt="Select program(s) to open: " --info=default --layout=reverse --tiebreak=index
}
selected=$(
# delete if database is older than 1day
if test "$(find "$TMPFILE" -mtime +1 2>/dev/null)" ; then
rm "$TMPFILE"
elif [ -f "$TMPFILE" ]; then
FZF_ARG < "$TMPFILE" | awk '{print $1}'
else
# if file does not exist then generate new database
find $(echo "$PATH" | sed 's@:@\n@g' | sed 's:/*$::' | awk '!x[$0]++' | sed ':a;N;$!ba;s/\n/\/* /g' ) -type f 2>/dev/null |
awk '!x[$0]++' | while read -r line
do
printf '%s\n' "$(basename "$line") $line"
done | sort > "$TMPFILE"
FZF_ARG < "$TMPFILE" | awk '{print $1}'
fi
)
[ -z "$selected" ] && exit
echo "$selected" | while read -r line; do
tmux new-window -n "${line}"
tmux send-keys -t "${line}" "$line" C-m
done