forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete typos using alias completion tech (apparently a complete rew…
…rite. Oops.)
- Loading branch information
Showing
1 changed file
with
26 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,32 @@ | ||
# shellcheck shell=bash | ||
about-plugin "Use cykerway's complete-alias project to complete aliases" | ||
# Load after all aliases and completions to understand what needs to be completed | ||
# BASH_IT_LOAD_PRIORITY: 800 | ||
|
||
# From https://github.com/cykerway/complete-alias | ||
# TODO: It'd be nice if this were bundled into the /vendor folder | ||
|
||
# TODO: it would be nice if this didn't also complete my typos (This will definitely requre coordination... unless I just declare the typo aliases... after this code runs (`BASH_IT_LOAD_PRIORITY: 801`)) | ||
# OOPS!!!!: all that does is mean that igt doesn't get complions for commit/push/pull/etc. D'oh. | ||
|
||
function _use_complete_alias { | ||
# Configuration. User can choose a folder, filename, or the whole path. Whole path wins, and its value is written back over any that it superceded | ||
# We use local variables to 'shadow' the missing configuration variables and 'plaster-over' their missing-ness within this function | ||
if [ ! -v COMPLETE_ALIAS_DIR ]; then | ||
local COMPLETE_ALIAS_DIR="${HOME}/.complete-alias" | ||
about-plugin "Use complete-alias completion to also complete typos. Requires complete-alias completion and typos plugin" | ||
# Load after all aliases and completions, and *the complete-alias completion itself to understand what needs to be completed | ||
# BASH_IT_LOAD_PRIORITY: 810 | ||
|
||
# See complete-alias for more information. | ||
|
||
function _use_complete_typo { | ||
if ! _command_exists _complete_alias; then | ||
# We need the complete-alias completion | ||
# TODO: a shared library tech for these two | ||
_log_error "Please enable complete-alias completion to use this completion" | ||
return 1 | ||
fi | ||
if [ ! -v COMPLETE_ALIAS_FILENAME ]; then | ||
local COMPLETE_ALIAS_FILENAME="complete_alias" | ||
if ! _command_exists _typos-load; then | ||
# We need the jake-typos plugin | ||
# TODO: a shared library tech for these two | ||
_log_error "Please enable the typos plugin to use this completion" | ||
return 1 | ||
fi | ||
if [ ! -v COMPLETE_ALIAS_FILE ]; then | ||
local COMPLETE_ALIAS_FILE="${COMPLETE_ALIAS_DIR}/${COMPLETE_ALIAS_FILENAME}" | ||
fi | ||
|
||
# Re-read the dir and filename back from the ultimate configuration | ||
COMPLETE_ALIAS_DIR="$(dirname "${COMPLETE_ALIAS_FILE}")" | ||
COMPLETE_ALIAS_FILENAME="$(basename "${COMPLETE_ALIAS_FILE}")" | ||
|
||
if [[ -f "${COMPLETE_ALIAS_FILE}" ]]; then | ||
source "${COMPLETE_ALIAS_FILE}" | ||
|
||
# complete-alias cannot see into sudo commands, because the _sudo completion strips sudo from the command line | ||
# This helps complete-alias see into sudo-land | ||
# See https://github.com/cykerway/complete-alias#:~:text=why%20is-,sudo%20completion,-not%20working%20correctly | ||
if ! alias sudo &> /dev/null; then | ||
if [[ "${COMPLETE_ALIAS_SUDO:-true}" != "true" ]]; then | ||
_log_debug "sudo alias support disabled" | ||
else | ||
if [[ "${COMPLETE_ALIAS_SUDO}" != "true" ]]; then # acted by default | ||
_log_debug "Installing sudo alias. Set \$COMPLETE_ALIAS_SUDO to true to suppress this message, or false to disable this behavior" | ||
fi | ||
alias sudo=sudo | ||
fi | ||
fi | ||
complete -F _complete_typo "${!_BASH_IT_TYPOS[@]}" | ||
} | ||
|
||
complete -F _complete_alias "${!BASH_ALIASES[@]}" | ||
else | ||
local ALIAS_CLONE_COMMAND="git clone [email protected]:cykerway/complete-alias.git \"\${COMPLETE_ALIAS_DIR:-${COMPLETE_ALIAS_DIR}}\"" | ||
_log_error "please install complete-alias or point \$COMPLETE_ALIAS_FILE to the ${COMPLETE_ALIAS_FILENAME} file within the place you checked it out from" | ||
_log_error "You might try: ${ALIAS_CLONE_COMMAND}" | ||
fi | ||
function _complete_typo { | ||
( | ||
_typos-load | ||
_complete_alias | ||
) | ||
} | ||
|
||
_use_complete_alias | ||
|
||
_use_complete_typo |