summaryrefslogtreecommitdiff
path: root/tmuxsh/_applauncher,--.start.programs.in.new.window
blob: 5f9f8fcac0feee8ca700b4e2d7ef48fd9d24be27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/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