i want tab complete command screen -r
in ubuntu can recover previous screens more easily. know screen -x
command, still need screen -r
in situation more 1 screens exist.
i find tab completion feature not exist in every ubuntu machine. sometimes, in same machine, tab completion works bash shell fails zsh shell.
can tell me how configure tab completion feature bash , zsh in ubuntu?
===============================some facts================================
here useful facts found after asking question. think these facts can serve workarounds extent.
i find that, if don't have tab completion support, can use part of screen name recover screen. example, given screen 12354.pts-0.slave9
, can recover typing screen -r 1
if no other screen name starts 1.
as zsh, if can not tab complete screen -r 1
, can possibly tab complete screen -r 0
. here 0
comes substring pts-0
, means can use other parts of name tab completion.
it's possible complete rule added .bashrc, refer https://www.gnu.org/software/bash/manual/html_node/programmable-completion.html , https://www.gnu.org/software/bash/manual/html_node/programmable-completion-builtins.html
example bash complete script screen bash-completion:
# bash completion screen -*- shell-script -*- _screen_sessions() { local sessions=( $( command screen -ls | sed -ne \ 's|^\t\{1,\}\([0-9]\{1,\}\.[^\t]\{1,\}\).*'"$1"'.*$|\1|p' ) ) if [[ $cur == +([0-9])?(.*) ]]; # complete sessions including pid prefixes compreply=( $( compgen -w '${sessions[@]}' -- "$cur" ) ) else # create unique completions, dropping pids possible local -a res local tmp in ${sessions[@]}; res[${i/#+([0-9])./}]+=" $i" done in ${!res[@]}; [[ ${res[$i]} == \ *\ * ]] && tmp+=" ${res[$i]}" || tmp+=" $i" done compreply=( $( compgen -w '$tmp' -- "$cur" ) ) fi } && _screen() { local cur prev words cword _init_completion || return if ((cword > 2)); case ${words[cword-2]} in -[dd]) _screen_sessions return 0 ;; esac fi local (( i=1; <= cword; i++ )); case ${words[i]} in -r|-r|-d|-d|-x|-s|-c|-t|-e|-h|-p|-s|-t) (( i++ )) continue ;; -*) continue ;; esac _command_offset $i return done case $prev in -[rr]) # list detached _screen_sessions 'detached' return 0 ;; -[dd]) # list attached _screen_sessions 'attached' return 0 ;; -x) # list both _screen_sessions return 0 ;; -s) _shells return 0 ;; -c) _filedir return 0 ;; -t) _terms return 0 ;; -e|-h|-p|-s|-t) return 0 ;; esac if [[ "$cur" == -* ]]; compreply=( $( compgen -w '-a -a -c -d -d -e -f -fn -fa -h -i -ln -list -l -m -o -p -q -r -r -s -s -t -t -u -v -wipe -x -x --help --version' -- "$cur" ) ) fi } && complete -f _screen screen # ex: ts=4 sw=4 et filetype=sh
Comments
Post a Comment