From 27e89cf61dab7b92edd905a50df3429d51c65e79 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Fri, 27 Jul 2018 16:31:04 +0100 Subject: [PATCH 1/5] bash: add completion for sway --- completions/bash/sway | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 completions/bash/sway diff --git a/completions/bash/sway b/completions/bash/sway new file mode 100644 index 00000000..edd752cd --- /dev/null +++ b/completions/bash/sway @@ -0,0 +1,46 @@ +# sway(1) completion + +_sway() +{ + local cur prev + _get_comp_words_by_ref cur prev + + short=( + -h + -c + -C + -d + -v + -V + ) + + long=( + --help + --config + --validate + --debug + --version + --verbose + --get-socketpath + ) + + case $prev in + -c|--config) + _filedir + return + ;; + esac + + if [[ $cur == --* ]]; then + COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) + elif [[ $cur == -* ]]; then + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + else + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + COMPREPLY+=($(compgen -c -- "$cur")) + fi + +} && +complete -F _sway sway From 21609f8af26b51872ef045ec75cb543835961ead Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Fri, 27 Jul 2018 16:31:18 +0100 Subject: [PATCH 2/5] bash: add completion for swaymsg --- completions/bash/swaymsg | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 completions/bash/swaymsg diff --git a/completions/bash/swaymsg b/completions/bash/swaymsg new file mode 100644 index 00000000..8ec90b6f --- /dev/null +++ b/completions/bash/swaymsg @@ -0,0 +1,57 @@ +# swaymsg(1) completion + +_swaymsg() +{ + local cur prev + _get_comp_words_by_ref cur prev + + types=( + 'get_workspaces' + 'get_seats' + 'get_inputs' + 'get_outputs' + 'get_tree' + 'get_marks' + 'get_bar_config' + 'get_version' + 'get_clipboard' + ) + + short=( + -h + -q + -r + -s + -t + -v + ) + + long=( + --help + --quiet + --raw + --socket + --type + --verbose + ) + + case $prev in + -s|--socket) + _filedir + return + ;; + -t|--type) + COMPREPLY=($(compgen -W "${types[*]}" -- "$cur")) + return + ;; + esac + + if [[ $cur == --* ]]; then + COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) + else + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + fi + +} && +complete -F _swaymsg swaymsg From 4a8a19d21f91a3126d83ac42d6a96900f42ba64c Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Fri, 27 Jul 2018 16:31:30 +0100 Subject: [PATCH 3/5] bash: add completion for swaylock --- completions/bash/swaylock | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 completions/bash/swaylock diff --git a/completions/bash/swaylock b/completions/bash/swaylock new file mode 100644 index 00000000..33925480 --- /dev/null +++ b/completions/bash/swaylock @@ -0,0 +1,66 @@ +# swaylock(1) completion + +_swaylock() +{ + local cur prev + _get_comp_words_by_ref -n : cur prev + + short=( + -h + -c + -s + -t + -v + -i + -u + -f + ) + + long=( + --help + --color + --scaling + --tiling + --version + --image + --no-unlock-indicator + --daemonize + ) + + scaling=( + 'stretch' + 'fill' + 'fit' + 'center' + 'tile' + ) + + case $prev in + -c|--color) + return + ;; + --scaling) + COMPREPLY=($(compgen -W "${scaling[*]}" -- "$cur")) + return + ;; + -i|--image) + if grep -q : <<< "$cur"; then + output="${cur%%:*}:" + cur="${cur#*:}" + else + output= + fi + COMPREPLY=($(compgen -f -- "$cur")) + return + ;; + esac + + if [[ $cur == --* ]]; then + COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) + else + COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) + fi + +} && +complete -F _swaylock swaylock From c4b4da5dc4ba9c68ff28ba2a01566b760adf1f55 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Fri, 27 Jul 2018 16:31:39 +0100 Subject: [PATCH 4/5] bash: add completion for swayidle --- completions/bash/swayidle | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 completions/bash/swayidle diff --git a/completions/bash/swayidle b/completions/bash/swayidle new file mode 100644 index 00000000..a0cdc8b2 --- /dev/null +++ b/completions/bash/swayidle @@ -0,0 +1,48 @@ +# swaymsg(1) completion + +_swayidle() +{ + local cur prev + _get_comp_words_by_ref -n : cur prev + local prev2=${COMP_WORDS[COMP_CWORD-2]} + local prev3=${COMP_WORDS[COMP_CWORD-3]} + + events=( + 'timeout' + 'before-sleep' + ) + + short=( + -h + -d + ) + + if [ "$prev" = timeout ]; then + # timeout + return + elif [ "$prev2" = timeout ]; then + # timeout + COMPREPLY=($(compgen -c -- "$cur")) + return + elif [ "$prev3" = timeout ]; then + # timeout [resume ] + COMPREPLY=(resume) + # optional argument; no return here as user may skip 'resume' + fi + + case "$prev" in + resume) + COMPREPLY=($(compgen -c -- "$cur")) + return + ;; + before-sleep) + COMPREPLY=($(compgen -c -- "$cur")) + return + ;; + esac + + COMPREPLY+=($(compgen -W "${events[*]}" -- "$cur")) + COMPREPLY+=($(compgen -W "${short[*]}" -- "$cur")) + +} && +complete -F _swayidle swayidle From b9d531b3181a0877ea3b94d5f9aa5877bbddeb1b Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Fri, 27 Jul 2018 17:50:33 +0100 Subject: [PATCH 5/5] meson: install bash completion --- meson.build | 12 ++++++++++++ meson_options.txt | 1 + 2 files changed, 13 insertions(+) diff --git a/meson.build b/meson.build index 1cb40ade..5be1f8d2 100644 --- a/meson.build +++ b/meson.build @@ -191,3 +191,15 @@ if (get_option('zsh_completions')) install_data(zsh_files, install_dir: zsh_install_dir) endif + +if (get_option('bash_completions')) + bash_files = files( + 'completions/bash/sway', + 'completions/bash/swayidle', + 'completions/bash/swaylock', + 'completions/bash/swaymsg', + ) + bash_install_dir = datadir + '/bash-completion/completions' + + install_data(bash_files, install_dir: bash_install_dir) +endif diff --git a/meson_options.txt b/meson_options.txt index 6c7f241d..7a23c206 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,5 @@ option('sway_version', type : 'string', description: 'The version string reported in `sway --version`.') option('default_wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.') option('zsh_completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') +option('bash_completions', type: 'boolean', value: true, description: 'Install bash shell completions.') option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications')