-
-
Save nnutter/a53a1623f8a61a7083bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_tm_complete() { | |
local rx | |
local token=${COMP_WORDS[$COMP_CWORD]} | |
local IFS=$'\t' | |
local words | |
if [ $COMP_CWORD -eq 1 ]; then | |
words=$(tmux -q list-sessions 2> /dev/null | cut -f 1 -d ':' | tr "\n" " " | sed 's/ $//') | |
fi | |
if [ $COMP_CWORD -eq 2 ]; then | |
words=$(tmux list-windows -t ${COMP_WORDS[1]} 2> /dev/null | awk '{print $2}' | tr -d '*-' | tr "\n" " " | sed 's/ $//') | |
fi | |
local nocasematchWasOff=0 | |
shopt nocasematch >/dev/null || nocasematchWasOff=1 | |
(( nocasematchWasOff )) && shopt -s nocasematch | |
local w matches=() | |
if [[ $token == "" ]]; then | |
matches=($words) | |
else | |
for w in $words; do | |
rx=$(ruby -e "print '$token'.gsub(/\s+/,'').split('').join('.*')") | |
if [[ "$w" =~ $rx ]]; then | |
matches+=($w) | |
fi | |
done | |
fi | |
(( nocasematchWasOff )) && shopt -u nocasematch | |
COMPREPLY=("${matches[@]}") | |
} | |
complete -F _tm_complete tm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment