-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_find_replace_completions
116 lines (115 loc) · 5.21 KB
/
_find_replace_completions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202406121215-git
# @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.pro
# @@License : WTFPL
# @@ReadME : find_replace --help
# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments
# @@Created : Wednesday, Jun 12, 2024 12:15 EDT
# @@File : find_replace
# @@Description :
# @@Changelog :
# @@TODO : Better documentation
# @@Other :
# @@Resource :
# @@Terminal App : no
# @@sudo/root : no
# @@Template : completions/system
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_find_replace_completion() {
#####################################################################
local cur prev words cword opts split CONFDIR="" CONFFILE="" SEARCHDIR=""
local SHOW_COMP_OPTS="" NOOPTS="" SHORTOPTS="" LONGOPTS="" ARRAY="" LIST="" SHOW_COMP_OPTS_SEP=""
#####################################################################
_init_completion || return
#####################################################################
___jq() { jq -rc "$@" 2>/dev/null; }
___sed_env() { sed 's|"||g;s|.*=||g' 2>/dev/null || false; }
___ls() { ls -A "$1" 2>/dev/null | grep -v '^$' | grep '^' || false; }
___curl() { curl -q -LSsf --max-time 1 --retry 0 "$@" 2>/dev/null || return 1; }
___grep_file() { grep --no-filename -vsR '#' "$@" 2>/dev/null | grep '^' || return 1; }
___find_cmd() { find -L "${1:-$CONFDIR/}" -maxdepth ${3:-3} -type ${2:-f} 2>/dev/null | grep '^' || return 1; }
___find_rel() { find -L "${1:-$CONFDIR/}" -maxdepth ${3:-3} -type ${2:-f} -printf "%P\n" 2>/dev/null | grep '^' || return 1; }
___grep_env() { GREP_COLORS="" grep -shE '^.*=*..*$' "$1" 2>/dev/null | grep -v '^#' | grep "${2:-^}" | sed 's|"||g' 2>/dev/null | grep '^' || false; }
#####################################################################
cur="${COMP_WORDS[$COMP_CWORD]}"
prev="${COMP_WORDS[$COMP_CWORD - 1]}"
#####################################################################
CASJAYSDEVDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}"
#####################################################################
CONFFILE="settings.conf"
CONFDIR="$HOME/.config/myscripts/find_replace"
SEARCHDIR="${CONFDIR:-$HOME/.config/myscripts/find_replace}"
#####################################################################
SHOW_COMP_OPTS=""
#####################################################################
SHORTOPTS=""
SHORTOPTS+=""
#####################################################################
LONGOPTS="--completions --config --debug --dir --help --options --raw --version --silent --force --no- "
LONGOPTS+=""
#####################################################################
#NOOPTS="--no-* "
#####################################################################
ARRAY=""
ARRAY+=""
#####################################################################
LIST=""
LIST+=""
#####################################################################
if [ "$SHOW_COMP_OPTS" != "" ]; then
SHOW_COMP_OPTS_SEP="${SHOW_COMP_OPTS//,/ }"
compopt -o $SHOW_COMP_OPTS_SEP
fi
#####################################################################
if [[ ${cur} == --* ]]; then
COMPREPLY=($(compgen -W '${LONGOPTS}' -- ${cur}))
elif [[ ${cur} == -* ]]; then
if [ -n "$SHORTOPTS" ]; then
COMPREPLY=($(compgen -W '${SHORTOPTS}' -- ${cur}))
else
COMPREPLY=($(compgen -W '${LONGOPTS}' -- ${cur}))
fi
else
case "${prev:-${COMP_WORDS[1]}}" in
--completions)
prev=""
COMPREPLY=($(compgen -W 'long short list array' -- "$cur"))
;;
--config | --debug | --help | --options | --raw | --version)
COMPREPLY=($(compgen -W '${ARRAY} ${LONGOPTS} ${SHORTOPTS}' -- ${cur}))
return 0
;;
--no-*)
COMPREPLY=($(compgen -W '${NOOPTS}' -- "$cur"))
return 0
;;
--dir)
prev="dir"
[ "$cword" -le 2 ] && _filedir -d || COMPREPLY=($(compgen -W '${ARRAY}' -- "$cur"))
;;
*)
COMPREPLY=($(compgen -W '${ARRAY}' -- "$cur"))
return 0
;;
esac
fi
#
# [ "${ARRAY}" = "show__filedir" ] && _filedir
# [ ${cword} = 2 ] && _filedir && compopt -o nospace
# [ "${ARRAY}" != "" ] && COMPREPLY=($(compgen -W '${ARRAY}' -- "${cur}"))
# [ "${ARRAY}" = "show__none" ] && COMPREPLY=($(compgen -W '' -- "${cur}"))
# [ "${ARRAY}" = "show__commands" ] && COMPREPLY=($(compgen -c -- "${cur}"))
# [ $COMP_CWORD -eq 2 ] && COMPREPLY=($(compgen -W '{a..z} {A..Z} {0..9}' -o nospace -- "${cur}"))
# [ $COMP_CWORD -eq 3 ] && COMPREPLY=($(compgen -W '$(_filedir)' -o filenames -o dirnames -- "${cur}"))
# [ $COMP_CWORD -gt 3 ] && COMPREPLY=($(compgen -W '' -- "${cur}"))
# compopt -o nospace
} &&
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# enable completions
complete -F _find_replace_completion -o default find_replace
# ex: ts=2 sw=2 et filetype=sh