Last active
May 10, 2019 03:53
-
-
Save sinewalker/3ecfd880ae3e72b899f6a197b805c932 to your computer and use it in GitHub Desktop.
Bash completion for all files in all subdirectories of a directory
This file contains 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
function _subfiles() { | |
COMPREPLY=() | |
local CUR FILES | |
CUR="${COMP_WORDS[COMP_CWORD]}" | |
FILES="$(find ${_COMP_DIR}/* -type f|awk -F ${_COMP_DIR}/ '{print $2}')" | |
COMPREPLY=( $(compgen -W "${FILES}" -- ${CUR}) ) | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this TAB-completion bash function searches for all files that are children of
$_COMP_DIR
.This is not generic because
$_COMP_DIR
will be searched base on it's current value, not the one when the completion function was defined or specifed to bash withcomplete -F _subfiles somefunction
. So it will search whichever directory the current value of$_COMP_DIR
is at the time the function is called (i.e. when TAB is pressed to complete for whichever function it's bound to).So, you will need to copy this function for different specific completions (say, your key files):