3
我最近寫了一個方便的Zsh函數,它創建了一個沒有參數的新的tmux會話。如果提供了一個參數並且會話已經存在,它就會被附加。否則,使用提供的名稱創建新會話。寫一個ZSH自動完成功能
# If the session is in the list of current tmux sessions, it is attached. Otherwise, a new session
# is created and attached with the argument as its name.
ta() {
# create the session if it doesn't already exist
tmux has-session -t $1 2>/dev/null
if [[ $? != 0 ]]; then
tmux new-session -d -s $1
fi
# if a tmux session is already attached, switch to the new session; otherwise, attach the new
# session
if { [ "$TERM" = "screen" ] && [ -n "$TMUX" ]; } then
tmux switch -t $1
else
tmux attach -t $1
fi
}
這很好,但我想添加autocompletion它,所以當我點擊標籤鍵時,它會列出當前會話爲我。這是我到目前爲止:
# List all the the sessions' names.
tln() {
tmux list-sessions | perl -n -e'/^([^:]+)/ && print $1 . "\n"'
}
compctl -K tln ta
當我點擊標籤時,它列出了會話名稱,但它不允許我在它們之間切換。我錯過了什麼?
這樣做。謝謝您的幫助! – LandonSchropp