-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tmux completion #81
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,6 +364,7 @@ bashcomp_DATA = 2to3 \ | |
tcpnice \ | ||
timeout \ | ||
tipc \ | ||
tmux \ | ||
tracepath \ | ||
tshark \ | ||
tune2fs \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# tmux(1) completion | ||
|
||
_tmux() | ||
{ | ||
local cur prev opts onePrev | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add cword and words to local here |
||
_init_completion || return | ||
|
||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting COMPREPLY and cur here are not necessary |
||
onePrev="${COMP_WORDS[COMP_CWORD-1]}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is onePrev different from the already existing $prev? |
||
|
||
if [ "$COMP_CWORD" -ge 2 ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use $cword instead of $COMP_CWORD |
||
# Check if we want to list available sessions. We're going to assume | ||
# this is defined as: [ls | list-session] -t . | ||
local windowCommands currentSessions | ||
windowCommands=("ls", "list-sessions") | ||
|
||
prev="${COMP_WORDS[COMP_CWORD-2]}" | ||
if [ "$prev" = "attach" ] || [ "$prev" = "attach-session" ] ; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use words instead of COMP_WORDS and cword instead of COMP_CWORD. Also, rename this to something like preprev instead of overloading the usual definition of prev |
||
if [ "$onePrev" = "-t" ] ; then | ||
# Get a list of all session names. | ||
# We're assuming this output is in the form: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like there's a missing indent step within the if block here |
||
# 'name: more info' | ||
# We'll get the name by using cut--use ":" as a delimiter, and | ||
# print the first column. If there are no sessions, we expect the | ||
# following message on stderr: | ||
# 'failed to connect to server: Connection refused'. | ||
# In this case we'll return an empty list. | ||
# NB: Since the failed to connect message is displayed on stderr, | ||
# we need to pipe both stdout and stderr to cut. Therefore we are | ||
# piping with |& rather than just |. | ||
currentSessions=$(tmux ls |& cut -d : -f 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use "$1" instead of tmux |
||
if [ "${currentSessions[0]}" = "failed to connect to server" ]; \ | ||
then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary backslash, move "then" to previous line. Also, is "failed to connect to server" dependent on locale? |
||
# We don't want to display any options, so clear the array. | ||
currentSessions=$( ) | ||
fi | ||
COMPREPLY=($(compgen -W "${currentSessions}" -- ${cur})) | ||
return | ||
fi | ||
fi | ||
fi | ||
|
||
opts=" \ | ||
attach-session \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big fan of this long hardcoded list in the first place. Can't it be generated from somewhere? If not, please indent the options, and the backslashes are unnecessary I think. |
||
bind-key \ | ||
break-pane \ | ||
capture-pane \ | ||
choose-client \ | ||
choose-session \ | ||
choose-window \ | ||
clear-history \ | ||
clock-mode \ | ||
command-prompt \ | ||
confirm-before \ | ||
copy-buffer \ | ||
copy-mode \ | ||
delete-buffer \ | ||
detach-client \ | ||
display-message \ | ||
display-panes \ | ||
down-pane \ | ||
find-window \ | ||
has-session \ | ||
if-shell \ | ||
join-pane \ | ||
kill-pane \ | ||
kill-server \ | ||
kill-session \ | ||
kill-window \ | ||
last-window \ | ||
link-window \ | ||
list-buffers \ | ||
list-clients \ | ||
list-commands \ | ||
list-keys \ | ||
list-panes \ | ||
list-sessions \ | ||
list-windows \ | ||
load-buffer \ | ||
lock-client \ | ||
lock-server \ | ||
lock-session \ | ||
move-window \ | ||
new-session \ | ||
new-window \ | ||
next-layout \ | ||
next-window \ | ||
paste-buffer \ | ||
pipe-pane \ | ||
previous-layout \ | ||
previous-window \ | ||
refresh-client \ | ||
rename-session \ | ||
rename-window \ | ||
resize-pane \ | ||
respawn-window \ | ||
rotate-window \ | ||
run-shell \ | ||
save-buffer \ | ||
select-layout \ | ||
select-pane \ | ||
select-prompt \ | ||
select-window \ | ||
send-keys \ | ||
send-prefix \ | ||
server-info \ | ||
set-buffer \ | ||
set-environment \ | ||
set-option \ | ||
set-window-option \ | ||
show-buffer \ | ||
show-environment \ | ||
show-messages \ | ||
show-options \ | ||
show-window-options \ | ||
source-file \ | ||
split-window \ | ||
start-server \ | ||
suspend-client \ | ||
swap-pane \ | ||
swap-window \ | ||
switch-client \ | ||
unbind-key \ | ||
unlink-window \ | ||
up-pane" | ||
|
||
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $cur in double quotes |
||
return | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary return and empty line |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "} &&" here, see existing completions |
||
complete -F _tmux tmux | ||
|
||
# ex: filetype=sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
-*- shell-script -*-
, see existing completions