From 2a583f1920fc7489206b543e12fb06ba8b4ff098 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Wed, 17 Jul 2024 17:19:07 -0600 Subject: [PATCH] Bash: please completion --- bash/.bash_aliases | 2 ++ bash/.bash_functions | 33 +++++++++++++++++++++++++++++++++ bash/.bash_profile | 1 + 3 files changed, 36 insertions(+) diff --git a/bash/.bash_aliases b/bash/.bash_aliases index 0b77ee1..e0cd308 100644 --- a/bash/.bash_aliases +++ b/bash/.bash_aliases @@ -33,7 +33,9 @@ alias ra='rg --no-ignore -.' alias ee='exit' alias ffprobe='ffprobe -hide_banner' alias shm='cd /dev/shm' +alias avada-kedavra='kill -9' alias ip='ip -color' +alias ip6='ip -color -6' # =================================================================== diff --git a/bash/.bash_functions b/bash/.bash_functions index a945105..0073039 100644 --- a/bash/.bash_functions +++ b/bash/.bash_functions @@ -282,6 +282,17 @@ function bless () { } # Attach to tmux session ============================================ +function _ta() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts=$(tmux ls | awk 'match($0, /^[^:]*: /) { print substr($0, RSTART, RLENGTH-2) }') + + COMPREPLY+=( $(compgen -W "$opts" -- ${cur}) ) + return 0 +} + function ta() { if [[ -n "$1" ]]; then tmux new -As "$1" @@ -295,6 +306,8 @@ function ta() { fi } +complete -F _ta ta + # Image magick ====================================================== function magika() { if [[ "$1" == "a" || "$1" == "av1" ]]; then @@ -354,4 +367,24 @@ rooter() { return 1 } +# Completion for please ============================================= +_please() { + local cur prev words cword + _init_completion || return + + # Complete command in first argument position + if [ $cword -eq 1 ]; then + COMPREPLY=($(compgen -c -- "$cur")) + return 0 + fi + + # Remove first word (please) + words=("${words[@]:1}") + (( cword-- )) + + # Run the completion for the command after 'please' + _command_offset 1 +} +complete -F _please please + # vim: set ft=bash ff=unix: diff --git a/bash/.bash_profile b/bash/.bash_profile index 4ef08f7..f9feced 100644 --- a/bash/.bash_profile +++ b/bash/.bash_profile @@ -13,6 +13,7 @@ source_completion_scripts () { if [[ "$(type -t _fzf_setup_completion)" == 'function' ]]; then _fzf_setup_completion path mpv vi vii nvim vimiv cat + _fzf_setup_completion proc avada-kedavra fi }