fixes and improvements
This commit is contained in:
25
tmux/.is_vim.sh
Executable file
25
tmux/.is_vim.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: is_vim.sh <tty>
|
||||
# tty: Specify tty to check for vim process.
|
||||
tty=$1
|
||||
|
||||
# Construct process tree.
|
||||
children=();
|
||||
pids=( $(ps -o pid= -t $tty) )
|
||||
|
||||
while read -r pid ppid
|
||||
do
|
||||
[[ -n pid && pid -ne ppid ]] && children[ppid]+=" $pid"
|
||||
done <<< "$(ps -Ao pid=,ppid=)"
|
||||
|
||||
# Get all descendant pids of processes in $tty with BFS
|
||||
idx=0
|
||||
while (( ${#pids[@]} > idx ))
|
||||
do
|
||||
pid=${pids[idx++]}
|
||||
pids+=( ${children[pid]-} )
|
||||
done
|
||||
|
||||
# Check whether any child pids are vim
|
||||
ps -o state=,comm= -p "${pids[@]}" | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'
|
||||
exit $?
|
||||
@@ -29,8 +29,8 @@ set -g @tmux_window_name_shells "['bash', 'fish', 'sh', 'zsh']"
|
||||
set -g @tmux_window_dir_programs "['nvim', 'vim', 'vi', 'git']"
|
||||
set -g @tmux_window_name_use_tilde "True"
|
||||
set -g @tmux_window_name_max_name_len "100"
|
||||
set-option -g default-shell $SHELL
|
||||
set -g default-command "$SHELL -i"
|
||||
# set-option -g default-shell $SHELL
|
||||
# set -g default-command "$SHELL -i"
|
||||
|
||||
# Other examples:
|
||||
# set -g @plugin 'github_username/plugin_name'
|
||||
@@ -61,8 +61,12 @@ setw -g mode-keys vi
|
||||
# decide whether we're in a Vim process
|
||||
#is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
|
||||
# | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
|
||||
is_vim="~/.is_vim.sh '#{pane_tty}'"
|
||||
# is_vim="children=(); i=0; pids=( $(ps -o pid=,tty= | grep -iE '#{s|/dev/||:pane_tty}' | awk '\{print $1\}') ); \
|
||||
# while read -r c p; do [[ -n c && c -ne p && p -ne 0 ]] && children[p]+=\" $\{c\}\"; done <<< \"$(ps -Ao pid=,ppid=)\"; \
|
||||
# while (( $\{#pids[@]\} > i )); do pid=$\{pids[i++]\}; pids+=( $\{children[pid]-\} ); done; \
|
||||
# ps -o state=,comm= -p \"$\{pids[@]\}\" | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
|
||||
|
||||
is_vim="~/is_vim.sh '#{pane_tty}'"
|
||||
|
||||
bind-key -n 'S-Left' if-shell "$is_vim" 'send-keys S-Left' 'select-pane -L'
|
||||
bind-key -n 'S-Down' if-shell "$is_vim" 'send-keys S-Down' 'select-pane -D'
|
||||
|
||||
Reference in New Issue
Block a user