Skip to content

Commit

Permalink
Use simple commands (cut, head and tail)
Browse files Browse the repository at this point in the history
Instead of the powerful sed
  • Loading branch information
isidroas authored and sainnhe committed Apr 15, 2024
1 parent 608356a commit 231c835
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$CURRENT_DIR/.envs"

target_origin=$(tmux list-commands)
target=$(printf "[cancel]\n%s" "$target_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS" | grep -o '^[^[:blank:]]*')
target=$(printf "[cancel]\n%s" "$target_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS" | cut -d ' ' -f 1)

[[ "$target" == "[cancel]" || -z "$target" ]] && exit
tmux command-prompt -I "$target"
4 changes: 1 addition & 3 deletions scripts/keybinding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ target=$(tmux list-keys | sed '1s/^/[cancel]\n/' | eval "$TMUX_FZF_BIN $TMUX_FZF
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
if [[ -n $(echo "$target" | grep -o "copy-mode") && -z $(echo "$target" | grep -o "prefix") ]]; then
tmux copy-mode
echo "$target" | sed -E 's/^.{46}//g' | xargs tmux
else
echo "$target" | sed -E 's/^.{46}//g' | xargs tmux
fi
echo "$target" | awk '{ $1=$2=$3=$4=""; print $0 }' | sed 's/^ *//' | xargs tmux
13 changes: 6 additions & 7 deletions scripts/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ source "$CURRENT_DIR/.envs"

# get front end list
tmux_fzf_menu_origin=$TMUX_FZF_MENU
front_end_list=$(echo -e "$tmux_fzf_menu_origin" | sed -n '1p')
tmux_fzf_menu_origin=$(echo -e "$tmux_fzf_menu_origin" | sed '1,2d')
while [[ $(echo -e "$tmux_fzf_menu_origin" | wc -l | xargs) != "0" && $(echo -e "$tmux_fzf_menu_origin" | wc -l | xargs) != "1" ]]; do
front_end_list="$front_end_list\n"$(echo -e "$tmux_fzf_menu_origin" | sed -n '1p')
tmux_fzf_menu_origin=$(echo -e "$tmux_fzf_menu_origin" | sed '1,2d')
front_end_list=$(echo -e "$tmux_fzf_menu_origin" | head -1 )$'\n'
tmux_fzf_menu_origin=$(echo -e "$tmux_fzf_menu_origin" | tail -n +3 )
while [ $(echo -ne "$tmux_fzf_menu_origin" | wc -l ) -ge 2 ]; do
front_end_list+=$(echo "$tmux_fzf_menu_origin" | head -1)$'\n'
tmux_fzf_menu_origin=$(echo "$tmux_fzf_menu_origin" | tail -n +3)$'\n'
done
front_end_list=$(echo -e "$front_end_list" | sed '/^[[:space:]]*$/d')

target=$(printf "%s\n[cancel]" "$front_end_list" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
target=$(printf "%s[cancel]" "$front_end_list" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")

[[ "$target" == "[cancel]" || -z "$target" ]] && exit
# get the next line in $TMUX_FZF_MENU and execute
Expand Down

0 comments on commit 231c835

Please sign in to comment.