-
Notifications
You must be signed in to change notification settings - Fork 1
/
sequence-commands.bash
134 lines (106 loc) · 3 KB
/
sequence-commands.bash
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# SPDX-License-Identifier: CC0-1.0
function mkdir-cd() {
#region args
local pathname || return
case $# in
(0)
{
printf '%s: missing argument: <pathname>\n' "${FUNCNAME[0]}"
printf 'usage: %s <pathname>\n' "${FUNCNAME[0]}"
} >&2
return 3
;;
(1)
if [ -z "$1" ]; then
printf '%s: argument must not be empty\n' "${FUNCNAME[0]}" >&2
return 9
fi
pathname="$1" || return
;;
(*)
{
printf '%s: too many arguments: %i\n' "${FUNCNAME[0]}" $#
printf 'usage: %s <pathname>\n' "${FUNCNAME[0]}"
} >&2
return 3
;;
esac
readonly pathname || return
#endregion
# shellcheck disable=2164
mkdir -p -- "$pathname" &&
cd -- "$pathname"
}
if command -v codium > '/dev/null'; then
function cd-codium() {
if ! command -v codium > '/dev/null'; then
printf '%s: codium: program missing\n' "${FUNCNAME[0]}" >&2
return 27
fi
cd "$@" &&
codium '.'
}
function mkdir-cd-codium() {
if ! command -v codium > '/dev/null'; then
printf '%s: codium: program missing\n' "${FUNCNAME[0]}" >&2
return 27
fi
#region args
local pathname || return
case $# in
(0)
{
printf '%s: missing argument: <pathname>\n' "${FUNCNAME[0]}"
printf 'usage: %s <pathname>\n' "${FUNCNAME[0]}"
} >&2
return 3
;;
(1)
if [ -z "$1" ]; then
printf '%s: argument must not be empty\n' "${FUNCNAME[0]}" >&2
return 9
fi
pathname="$1" || return
;;
(*)
{
printf '%s: too many arguments: %i\n' "${FUNCNAME[0]}" $#
printf 'usage: %s <pathname>\n' "${FUNCNAME[0]}"
} >&2
return 3
;;
esac
readonly pathname || return
#endregion
mkdir -p -- "$pathname" &&
cd -- "$pathname" &&
codium '.'
}
fi
#region completion
if [ -f '/usr/share/bash-completion/completions/mkdir' ]; then
# shellcheck disable=1091
. '/usr/share/bash-completion/completions/mkdir'
fi
declare __dotfiles_bash_funcs_sequence_commands__mkdir_complete
__dotfiles_bash_funcs_sequence_commands__mkdir_complete="$(complete | grep -E '^complete( .*)? mkdir$')"
if [ -n "$__dotfiles_bash_funcs_sequence_commands__mkdir_complete" ]; then
eval "${__dotfiles_bash_funcs_sequence_commands__mkdir_complete}-cd"
fi
if command -v cd-codium > '/dev/null'; then
if [ -f '/usr/share/bash-completion/completions/cd' ]; then
# shellcheck disable=1091
. '/usr/share/bash-completion/completions/cd'
fi
declare __dotfiles_bash_funcs_sequence_commands__cd_complete
__dotfiles_bash_funcs_sequence_commands__cd_complete="$(complete | grep -E '^complete( .*)? cd$')"
if [ -n "$__dotfiles_bash_funcs_sequence_commands__cd_complete" ]; then
eval "${__dotfiles_bash_funcs_sequence_commands__cd_complete}-codium"
fi
unset -v __dotfiles_bash_funcs_sequence_commands__cd_complete
fi
if command -v mkdir-cd-codium > '/dev/null' && [ -n "$__dotfiles_bash_funcs_sequence_commands__mkdir_complete" ]; then
eval "${__dotfiles_bash_funcs_sequence_commands__mkdir_complete}-cd-codium"
fi
unset -v __dotfiles_bash_funcs_sequence_commands__mkdir_complete
#endregion