Skip to content

Commit

Permalink
feat: fzf header
Browse files Browse the repository at this point in the history
  • Loading branch information
sainnhe committed Apr 25, 2019
1 parent 6d282df commit af68bac
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Manage panes ( switch, break, join*, swap, layout, kill* ).
- Multiple selection ( support for actions marked by * ).
- Search commands and append to command prompt.
- Search keys and execute.
- Search key bindings and execute.

# Installation

Expand Down
Binary file modified demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion main.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ITEMS_ORIGIN=$(printf "session\nwindow\npane\ncommand\nkey")
ITEMS_ORIGIN=$(printf "session\nwindow\npane\ncommand\nkeybinding")
ITEM=$(printf "%s\n[cancel]" "$ITEMS_ORIGIN" | "$CURRENT_DIR/scripts/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$ITEM" == "[cancel]" ]]; then
exit
Expand Down
1 change: 1 addition & 0 deletions scripts/command.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select a command"')
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_ORIGIN=$(tmux list-commands)
TARGET=$(printf "[cancel]\n%s" "$TARGET_ORIGIN" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS" | grep -o '^[^[:blank:]]*')
Expand Down
1 change: 1 addition & 0 deletions scripts/key.sh → scripts/keybinding.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select a key binding"')
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_ORIGIN=$(tmux list-keys | sed '1i [cancel]' | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$TARGET_ORIGIN" == "[cancel]" ]]; then
Expand Down
9 changes: 9 additions & 0 deletions scripts/pane.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ else
PANES=$(tmux list-panes -a -F "#S:#{window_index}.#{pane_index}: $TMUX_FZF_PANE_FORMAT")
fi

FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select an action"')
ACTION=$(printf "switch\nbreak\njoin\nswap\nlayout\nkill\n[cancel]" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$ACTION" == "[cancel]" ]]; then
exit
elif [[ "$ACTION" == "layout" ]]; then
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select a layout"')
TARGET_ORIGIN=$(printf "even-horizontal\neven-vertical\nmain-horizontal\nmain-vertical\ntiled\n[cancel]" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$TARGET_ORIGIN" == "[cancel]" ]]; then
exit
else
tmux select-layout "$TARGET_ORIGIN"
fi
else
if [[ "$ACTION" == "join" || "$ACTION" == "kill" ]]; then
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select target pane(s), press TAB to select multiple targets"')
else
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select target pane"')
fi
TARGET_ORIGIN=$(printf "%s\n[cancel]" "$PANES" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$TARGET_ORIGIN" == "[cancel]" ]]; then
exit
Expand All @@ -32,6 +39,7 @@ else
echo "$TARGET" | sort -r | xargs -i tmux kill-pane -t {}
elif [[ "$ACTION" == "swap" ]]; then
PANES=$(echo "$PANES" | grep -v "^$TARGET")
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select another target pane"')
TARGET_SWAP_ORIGIN=$(printf "%s\n[cancel]" "$PANES" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$TARGET_SWAP_ORIGIN" == "[cancel]" ]]; then
exit
Expand All @@ -42,6 +50,7 @@ else
elif [[ "$ACTION" == "join" ]]; then
echo "$TARGET" | sort -r | xargs -i tmux move-pane -s {}
elif [[ "$ACTION" == "break" ]]; then
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select destination"')
DST_WIN=$(printf "after\nend\nbegin\n[cancel]" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
CUR_WIN_NUM=$(tmux display-message -p | grep -o '[[[:alpha:]|[:digit:]]*] [[:digit:]]*:' | sed -e 's/\[.*\] //' -e 's/.$//')
CUR_SES=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
Expand Down
11 changes: 9 additions & 2 deletions scripts/session.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ else
SESSIONS=$(tmux list-sessions -F "#S: $TMUX_FZF_SESSION_FORMAT")
fi

FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select an action"')
ACTION=$(printf "attach\ndetach\nrename\nkill\n[cancel]" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$ACTION" == "[cancel]" ]]; then
exit
else
if [[ "$ACTION" != "detach" ]]; then
if [[ "$ACTION" == "kill" ]]; then
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select target session(s), press TAB to select multiple targets"')
else
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select target session"')
fi
TARGET_ORIGIN=$(printf "%s\n[cancel]" "$SESSIONS" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
else
TMUX_DETACHED_SESSIONS=$(tmux list-sessions | grep -v 'attached' | grep -o '^[[:alpha:]|[:digit:]]*:' | sed 's/.$//g')
SESSIONS=$(echo "$SESSIONS" | grep -v "^$TMUX_DETACHED_SESSIONS")
TMUX_ATTACHED_SESSIONS=$(tmux list-sessions | grep 'attached' | grep -o '^[[:alpha:]|[:digit:]]*:' | sed 's/.$//g')
SESSIONS=$(echo "$SESSIONS" | grep "^$TMUX_ATTACHED_SESSIONS")
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select target session(s), press TAB to select multiple targets"')
TARGET_ORIGIN=$(printf "%s\n[cancel]" "$SESSIONS" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
fi
if [[ "$TARGET_ORIGIN" == "[cancel]" ]]; then
Expand Down
11 changes: 11 additions & 0 deletions scripts/window.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ else
WINDOWS=$(tmux list-windows -a -F "#S:#{window_index}: $TMUX_FZF_WINDOW_FORMAT")
fi

FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select an action"')
ACTION=$(printf "switch\nlink\nmove\nswap\nrename\nkill\n[cancel]" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$ACTION" == "[cancel]" ]]; then
exit
Expand All @@ -16,11 +17,13 @@ elif [[ "$ACTION" == "link" ]]; then
CUR_SES=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
LAST_WIN_NUM=$(tmux list-windows | sort -r | sed '2,$d' | sed 's/:.*//')
WINDOWS=$(echo "$WINDOWS" | grep -v "^$CUR_SES")
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select source window"')
SRC_WIN_ORIGIN=$(printf "%s\n[cancel]" "$WINDOWS" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$SRC_WIN_ORIGIN" == "[cancel]" ]]; then
exit
else
SRC_WIN=$(echo "$SRC_WIN_ORIGIN" | grep -o '^[[:alpha:]|[:digit:]]*:[[:digit:]]*:' | sed 's/.$//g')
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select destination"')
DST_WIN_ORIGIN=$(printf "after\nend\nbegin\n[cancel]" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$DST_WIN_ORIGIN" == "[cancel]" ]]; then
exit
Expand All @@ -44,11 +47,13 @@ elif [[ "$ACTION" == "move" ]]; then
CUR_SES=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
LAST_WIN_NUM=$(tmux list-windows | sort -r | sed '2,$d' | sed 's/:.*//')
WINDOWS=$(echo "$WINDOWS" | grep -v "^$CUR_SES")
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select source window"')
SRC_WIN_ORIGIN=$(printf "%s\n[cancel]" "$WINDOWS" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$SRC_WIN_ORIGIN" == "[cancel]" ]]; then
exit
else
SRC_WIN=$(echo "$SRC_WIN_ORIGIN" | grep -o '^[[:alpha:]|[:digit:]]*:[[:digit:]]*:' | sed 's/.$//g')
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select destination"')
DST_WIN_ORIGIN=$(printf "after\nend\nbegin\n[cancel]" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$DST_WIN_ORIGIN" == "[cancel]" ]]; then
exit
Expand All @@ -68,6 +73,11 @@ elif [[ "$ACTION" == "move" ]]; then
fi
fi
else
if [[ "$ACTION" == "kill" ]]; then
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select target window(s), press TAB to select multiple targets"')
else
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select target window"')
fi
TARGET_ORIGIN=$(printf "%s\n[cancel]" "$WINDOWS" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$TARGET_ORIGIN" == "[cancel]" ]]; then
exit
Expand All @@ -79,6 +89,7 @@ else
tmux command-prompt -I "rename-window -t $TARGET "
elif [[ "$ACTION" == "swap" ]]; then
WINDOWS=$(echo "$WINDOWS" | grep -v "$TARGET")
FZF_DEFAULT_OPTS=$(echo $FZF_DEFAULT_OPTS | sed -r -e '$a --header="select another target window"')
TARGET_SWAP_ORIGIN=$(printf "%s\n[cancel]" "$WINDOWS" | "$CURRENT_DIR/.fzf-tmux" "$TMUX_FZF_OPTIONS")
if [[ "$TARGET_SWAP_ORIGIN" == "[cancel]" ]]; then
exit
Expand Down

0 comments on commit af68bac

Please sign in to comment.