Eu escrevi este widget zsh que melhora o uso de TAB, não apenas em uma linha vazia, mas também enquanto você está digitando um comando.
- Ele listará arquivos em uma linha de comando vazia e no meio de qualquer comando.
- Listará diretórios em uma linha de comando vazia.
- Ele listará executáveis em uma linha de comando vazia.
Pode ser configurado para preceder "cd" ou "./" nos casos com uma variável global.
export TAB_LIST_FILES_PREFIX
#Listfilesinzshwith<TAB>##Copyleft2017byIgnacioNunezHernanz<nacho_a_t_ownyourbits_d_o_t_com>#GPLlicensed(seeendoffile)*Useatyourownrisk!##Usage:#Inthemiddleofthecommandline:#(commandbeingtyped)<TAB>(resumetyping)##Atthebeginningofthecommandline:#<SPACE><TAB>#<SPACE><SPACE><TAB>##Notes:#Thisdoesnotaffectothercompletions#Ifyouwant'cd'or'./'tobeprepended,writeinyour.zshrc'exportTAB_LIST_FILES_PREFIX'#Irecommendtocomplementthiswithpush-line-oredit(bindkey'^q'push-line-or-edit)functiontab_list_files{if[[$#BUFFER==0]];thenBUFFER="ls "
CURSOR=3
zle list-choices
zle backward-kill-word
elif [[ $BUFFER =~ ^[[:space:]][[:space:]].*$ ]]; then
BUFFER="./"
CURSOR=2
zle list-choices
[ -z ${TAB_LIST_FILES_PREFIX+x} ] && BUFFER=" " CURSOR=2
elif [[ $BUFFER =~ ^[[:space:]]*$ ]]; then
BUFFER="cd "
CURSOR=3
zle list-choices
[ -z ${TAB_LIST_FILES_PREFIX+x} ] && BUFFER=" " CURSOR=1
else
BUFFER_=$BUFFER
CURSOR_=$CURSOR
zle expand-or-complete || zle expand-or-complete || {
BUFFER="ls "
CURSOR=3
zle list-choices
BUFFER=$BUFFER_
CURSOR=$CURSOR_
}
fi
}
zle -N tab_list_files
bindkey '^I' tab_list_files
# uncomment the following line to prefix 'cd ' and './'
# when listing dirs and executables respectively
#export TAB_LIST_FILES_PREFIX
# these two lines are usually included by oh-my-zsh, but just in case
autoload -Uz compinit
compinit
# uncomment the following line to complement tab_list_files with ^q
#bindkey '^q' push-line-or-edit
# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA