Skip to content
Snippets Groups Projects
Unverified Commit 9f9760de authored by hluk's avatar hluk Committed by GitHub
Browse files

Merge pull request #1548 from LiteracyFanatic/fix-completions

Namespace bash completions
parents cbe91cd4 1494ac77
No related branches found
No related tags found
No related merge requests found
# shellcheck shell=bash # shellcheck shell=bash
commands=( _copyq_commands=(
show hide toggle menu exit disable enable clipboard selection paste copy show hide toggle menu exit disable enable clipboard selection paste copy
count select next previous add insert remove edit separator read write count select next previous add insert remove edit separator read write
action popup tab removetab renametab exporttab importtab config eval session action popup tab removetab renametab exporttab importtab config eval session
help help
) )
list_sessions() { _copyq_list_sessions() {
ss -l -x | sed -nE 's#.*/\.copyq-?(\S*)_s .*#\1#p' ss -l -x | sed -nE 's#.*/\.copyq-?(\S*)_s .*#\1#p'
} }
complete_words() { _copyq_complete_words() {
while read -r item; do while read -r item; do
COMPREPLY+=("$item") COMPREPLY+=("$item")
done < <(compgen -W "$1" -- "${COMP_WORDS[$COMP_CWORD]}") done < <(compgen -W "$1" -- "${COMP_WORDS[$COMP_CWORD]}")
} }
complete_lines() { _copyq_complete_lines() {
while read -r item; do while read -r item; do
COMPREPLY+=("$item") COMPREPLY+=("$item")
done < <(IFS=$'\n' compgen -W "$1" -- "${COMP_WORDS[$COMP_CWORD]}") done < <(IFS=$'\n' compgen -W "$1" -- "${COMP_WORDS[$COMP_CWORD]}")
} }
complete_files() { _copyq_complete_files() {
while read -r item; do while read -r item; do
COMPREPLY+=("$item") COMPREPLY+=("$item")
done < <(compgen -f -- "${COMP_WORDS[$COMP_CWORD]}") done < <(compgen -f -- "${COMP_WORDS[$COMP_CWORD]}")
...@@ -34,13 +34,13 @@ _copyq_completions() { ...@@ -34,13 +34,13 @@ _copyq_completions() {
1) 1)
case "${COMP_WORDS[$COMP_CWORD]}" in case "${COMP_WORDS[$COMP_CWORD]}" in
--*) --*)
complete_words '--session --help' _copyq_complete_words '--session --help'
;; ;;
-*) -*)
complete_words '-e -s -h' _copyq_complete_words '-e -s -h'
;; ;;
*) *)
complete_words "${commands[*]}" _copyq_complete_words "${_copyq_commands[*]}"
;; ;;
esac esac
;; ;;
...@@ -48,55 +48,55 @@ _copyq_completions() { ...@@ -48,55 +48,55 @@ _copyq_completions() {
case "${COMP_WORDS[$COMP_CWORD-1]}" in case "${COMP_WORDS[$COMP_CWORD-1]}" in
show) show)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq tab)" _copyq_complete_lines "$(copyq tab)"
;; ;;
clipboard) clipboard)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq clipboard -- ?)" _copyq_complete_lines "$(copyq clipboard -- ?)"
;; ;;
selection) selection)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq selection -- ?)" _copyq_complete_lines "$(copyq selection -- ?)"
;; ;;
copy) copy)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq clipboardFormatsToSave)" _copyq_complete_lines "$(copyq clipboardFormatsToSave)"
;; ;;
read) read)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq read -- ?)" _copyq_complete_lines "$(copyq read -- ?)"
;; ;;
write) write)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq clipboardFormatsToSave)" _copyq_complete_lines "$(copyq clipboardFormatsToSave)"
;; ;;
tab) tab)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq tab)" _copyq_complete_lines "$(copyq tab)"
;; ;;
removetab) removetab)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq tab)" _copyq_complete_lines "$(copyq tab)"
;; ;;
renametab) renametab)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq tab)" _copyq_complete_lines "$(copyq tab)"
;; ;;
exporttab) exporttab)
complete_files _copyq_complete_files
;; ;;
importtab) importtab)
complete_files _copyq_complete_files
;; ;;
config) config)
pidof copyq &>/dev/null || return pidof copyq &>/dev/null || return
complete_lines "$(copyq config | grep '^[^ ]')" _copyq_complete_lines "$(copyq config | grep '^[^ ]')"
;; ;;
session|-s|--session) session|-s|--session)
complete_lines "$(list_sessions)" _copyq_complete_lines "$(_copyq_list_sessions)"
;; ;;
help|-h|--help) help|-h|--help)
complete_words "${commands[*]}" _copyq_complete_words "${_copyq_commands[*]}"
;; ;;
esac esac
;; ;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment