aboutsummaryrefslogtreecommitdiffhomepage
path: root/hyprpm/hyprpm.bash
diff options
context:
space:
mode:
authorLOSEARDES77 <[email protected]>2024-04-07 18:39:46 +0200
committerGitHub <[email protected]>2024-04-07 19:39:46 +0300
commit20899d0df2a2811d83b4ae3357ad31a94eafcd8e (patch)
treee68ecef72e686d9b0259f311e577b1a27fb12910 /hyprpm/hyprpm.bash
parentb50182326cd157f8d5bc3ace9dc5660aa8244bf6 (diff)
downloadHyprland-20899d0df2a2811d83b4ae3357ad31a94eafcd8e.tar.gz
Hyprland-20899d0df2a2811d83b4ae3357ad31a94eafcd8e.zip
hyprpm: add shell completions (#5423)
* hyprpm: add completions * hyprctl: correct spell mistakes * Apply fixes * makefile: correct shell completion paths * makefile: remove complletions on uninstalling
Diffstat (limited to 'hyprpm/hyprpm.bash')
-rw-r--r--hyprpm/hyprpm.bash106
1 files changed, 106 insertions, 0 deletions
diff --git a/hyprpm/hyprpm.bash b/hyprpm/hyprpm.bash
new file mode 100644
index 00000000..6989f7c1
--- /dev/null
+++ b/hyprpm/hyprpm.bash
@@ -0,0 +1,106 @@
+_hyprpm_cmd_0 () {
+ hyprpm list | grep Plugin | awk '{print $4}'
+}
+
+_hyprpm () {
+ if [[ $(type -t _get_comp_words_by_ref) != function ]]; then
+ echo _get_comp_words_by_ref: function not defined. Make sure the bash-completions system package is installed
+ return 1
+ fi
+
+ local words cword
+ _get_comp_words_by_ref -n "$COMP_WORDBREAKS" words cword
+
+ local -a literals=("-n" "::=" "list" "disable" "--help" "update" "add" "--verbose" "-v" "--force" "remove" "enable" "--notify" "-h" "reload" "-f")
+
+ declare -A literal_transitions
+ literal_transitions[0]="([9]=6 [2]=2 [7]=6 [8]=6 [4]=6 [10]=2 [11]=3 [5]=2 [13]=6 [3]=3 [14]=2 [15]=6 [6]=2)"
+ literal_transitions[1]="([10]=2 [11]=3 [3]=3 [2]=2 [14]=2 [5]=2 [6]=2)"
+ literal_transitions[4]="([1]=5)"
+ literal_transitions[5]="([0]=6 [12]=6)"
+
+ declare -A match_anything_transitions
+ match_anything_transitions=([3]=2 [2]=4 [0]=1 [1]=1)
+ declare -A subword_transitions
+
+ local state=0
+ local word_index=1
+ while [[ $word_index -lt $cword ]]; do
+ local word=${words[$word_index]}
+
+ if [[ -v "literal_transitions[$state]" ]]; then
+ declare -A state_transitions
+ eval "state_transitions=${literal_transitions[$state]}"
+
+ local word_matched=0
+ for literal_id in $(seq 0 $((${#literals[@]} - 1))); do
+ if [[ ${literals[$literal_id]} = "$word" ]]; then
+ if [[ -v "state_transitions[$literal_id]" ]]; then
+ state=${state_transitions[$literal_id]}
+ word_index=$((word_index + 1))
+ word_matched=1
+ break
+ fi
+ fi
+ done
+ if [[ $word_matched -ne 0 ]]; then
+ continue
+ fi
+ fi
+
+ if [[ -v "match_anything_transitions[$state]" ]]; then
+ state=${match_anything_transitions[$state]}
+ word_index=$((word_index + 1))
+ continue
+ fi
+
+ return 1
+ done
+
+
+ local prefix="${words[$cword]}"
+
+ local shortest_suffix="$word"
+ for ((i=0; i < ${#COMP_WORDBREAKS}; i++)); do
+ local char="${COMP_WORDBREAKS:$i:1}"
+ local candidate="${word##*$char}"
+ if [[ ${#candidate} -lt ${#shortest_suffix} ]]; then
+ shortest_suffix=$candidate
+ fi
+ done
+ local superfluous_prefix=""
+ if [[ "$shortest_suffix" != "$word" ]]; then
+ local superfluous_prefix=${word%$shortest_suffix}
+ fi
+
+ if [[ -v "literal_transitions[$state]" ]]; then
+ local state_transitions_initializer=${literal_transitions[$state]}
+ declare -A state_transitions
+ eval "state_transitions=$state_transitions_initializer"
+
+ for literal_id in "${!state_transitions[@]}"; do
+ local literal="${literals[$literal_id]}"
+ if [[ $literal = "${prefix}"* ]]; then
+ local completion=${literal#"$superfluous_prefix"}
+ COMPREPLY+=("$completion ")
+ fi
+ done
+ fi
+ declare -A commands
+ commands=([3]=0)
+ if [[ -v "commands[$state]" ]]; then
+ local command_id=${commands[$state]}
+ local completions=()
+ mapfile -t completions < <(_hyprpm_cmd_${command_id} "$prefix" | cut -f1)
+ for item in "${completions[@]}"; do
+ if [[ $item = "${prefix}"* ]]; then
+ COMPREPLY+=("$item")
+ fi
+ done
+ fi
+
+
+ return 0
+}
+
+complete -o nospace -F _hyprpm hyprpm