Created
April 3, 2021 03:21
-
-
Save SomajitDey/3fdec7fd084601ae10132697dcbb9d9e to your computer and use it in GitHub Desktop.
Shell-function to give current word of Bash readline, i.e. "read -e". To be used with key-binding for custom TAB completion
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
### Source me | |
readline_cword(){ | |
# Gives current word of Bash readline, viz. the word where the insertion point/cursor is currently at | |
set -- ${READLINE_LINE} | |
local length=${#1} | |
while ((length < READLINE_POINT)); do | |
shift | |
length+=${#1} | |
done | |
echo -n "${1}" | |
}; export -f readline_cword | |
# Use case: | |
# Custom TAB completion: | |
# Single TAB: bind -x '"\t":custom__completion_function "$(readline_cword)"' | |
# Double TAB: bind -x '"\t\t":custom__list_suggestions_function "$(readline_cword)"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment