-
Notifications
You must be signed in to change notification settings - Fork 0
/
gchmod
executable file
·175 lines (144 loc) · 4.62 KB
/
gchmod
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/bash
# Author: zenobit
# Description: Uses gum to provide a simple TUI
# License MIT
# - CHANGE all X to whats needed
# color
c="#295340"
# gum filter
export GUM_FILTER_INDICATOR_FOREGROUND=${c}
export GUM_FILTER_SELECTED_PREFIX_FOREGROUND=${c}
export GUM_FILTER_HEADER_FOREGROUND=${c}
export GUM_FILTER_CURSOR_TEXT_FOREGROUND=${c}
# gum style
export GUM_STYLE_FOREGROUND=${c}
# filter height
h=10
header() {
gum style \
--padding '0 1' \
--border rounded \
--align center \
--border-foreground $c \
"\
TUI for chmod
Change the mode of each FILE to MODE.
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
or: chmod [OPTION]... OCTAL-MODE FILE...
or: chmod [OPTION]... --reference=RFILE FILE...
With --reference, change the mode of each FILE to that of RFILE.
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/chmod>
or available locally via: info '(coreutils) chmod invocation'
Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'"
}
header
choice=$(echo "\
-c --changes like verbose but report only when a change is made
-f --silent --quiet suppress most error messages
-v --verbose output a diagnostic for every file processed
--no-preserve-root do not treat '/' specially (the default)
--preserve-root fail to operate recursively on '/'
--reference=RFILE use RFILE's mode instead of specifying MODE values. RFILE is always dereferenced if a symbolic link.
-R --recursive change files and directories recursively
--help display help and exit
--version output version information and exit
MAN Show chmod man page" | gum filter --header "Action..." --height $h)
gum_X() {
tmp="$tmpdir/tmp-X"
headertext="
Choosed: $(cat ${tmp})"
header
h=X
choice=$(echo "\
+
-" | gum filter --no-fuzzy --header "Choosed: $(cat ${tmp})" --height ${h})
ch=$(echo ${choice} | cut -d' ' -f1)
if [ ${ch} == 'ENOUGH' ]; then
echo -e "\nUsing:\n gum $(cat ${tmp})\n"
arguments=($(cat ${tmp}))
gum "${arguments[@]}" XXXX #"$(gum file --file=no --directory)"
else
echo -n "${ch} " >> ${tmp}
gum_X
fi
}
gum_X() {
tmp="$tmpdir/tmp-X"
headertext="
Choosed: $(cat ${tmp})"
header
h=3
choice=$(echo "\
a Give the [a]ll
u Give the [u]ser
g Give the [g]roup
o Give [o]thers" | gum filter --no-fuzzy --height ${h})
ch=$(echo ${choice} | cut -d' ' -f1)
if [ ${ch} == 'ENOUGH' ]; then
echo -e "\nUsing:\n gum $(cat ${tmp})\n"
arguments=($(cat ${tmp}))
gum "${arguments[@]}" XXXX #"$(gum file --file=no --directory)"
else
echo -n "${ch} " >> ${tmp}
gum_X
fi
}
gum_X() {
tmp="$tmpdir/tmp-X"
headertext="
Choosed: $(cat ${tmp})"
header
h=3
choice=$(echo "\
r rights to [r]ead
w rights to [w]rite
x rights to e[x]ecute" | gum filter --no-fuzzy --height ${h})
ch=$(echo ${choice} | cut -d' ' -f1)
if [ ${ch} == 'ENOUGH' ]; then
echo -e "\nUsing:\n gum $(cat ${tmp})\n"
arguments=($(cat ${tmp}))
gum "${arguments[@]}" XXXX #"$(gum file --file=no --directory)"
else
echo -n "${ch} " >> ${tmp}
gum_X
fi
}
chmod $(echo ${choice} | cut -d' ' -f1) ${1} || echo "No argument provided!"
u+x Give the [u]ser who owns a file the right to e[x]ecute it
u+rw Give the [u]ser rights to [r]ead and [w]rite to a file/directory
g-x Remove e[x]ecutable rights from the [g]roup
a+rx Give [a]ll users rights to [r]ead and e[x]ecute
o=g Give [o]thers (not in the file owner's group) the same rights as the [g]roup
o= Remove all rights from [o]thers
g+w,o+w Change permissions giving [g]roup and [o]thers the ability to [w]rite
a+rX Give [a]ll users [r]ead permissions to files and e[X]ecute permissions to sub-directories within a di
rectory
gum_chmod() {
echo "Welcome to the chmod TUI (Text User Interface)"
read -p "Enter the file/directory path: " filepath
# Collect permission values
read -p "Read permission for owner (y/n): " read_perm_owner
read -p "Write permission for owner (y/n): " write_perm_owner
read -p "Execute permission for owner (y/n): " execute_perm_owner
# ... similarly for group and others
# Construct the chmod command
chmod_command="chmod"
# Owner permissions
if [ "$read_perm_owner" == "y" ]; then
chmod_command+=" +r"
fi
if [ "$write_perm_owner" == "y" ]; then
chmod_command+=" +w"
fi
if [ "$execute_perm_owner" == "y" ]; then
chmod_command+=" +x"
fi
# ... similarly for group and others
# Apply permissions to the file/directory
chmod_command+=" $filepath"
# Run the chmod command
echo "Executing: $chmod_command"
eval $chmod_command
echo "chmod operation complete"
}