-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtrls.sh
314 lines (290 loc) · 7.29 KB
/
btrls.sh
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/bash
# Define icons for different file types
declare -A icons=(
["folder"]="\033[1;96m "
[".asm"]=" "
[".awk"]=" "
[".bash"]=" "
[".bash_aliases"]=" "
[".bash_profile"]=" "
[".bash_history"]=" "
[".bashrc"]=" "
[".bin"]=" "
[".bmp"]=" "
[".bz"]=" "
[".bz2"]=" "
[".c"]=" "
[".class"]=" "
[".conf"]=" "
[".cfg"]=" "
[".cp"]=" "
[".cpp"]=" "
[".css"]=" "
[".csv"]=" "
[".dart"]=" "
[".db"]=""
[".deb"]=" "
[".doc"]=" "
[".docx"]=" "
[".ejs"]=" "
[".el"]=" "
[".emacs"]=" "
[".eot"]=" "
[".epub"]=" "
[".erb"]=" "
[".ex"]=" "
[".exs"]=" "
[".fish"]=" "
[".fs"]=" "
[".fsi"]=" "
[".fsx"]=" "
[".gif"]=" "
[".git"]=" "
[".gitattributes"]=" "
[".gitconfig"]=" "
[".gitignore"]=" "
[".gitmodules"]=" "
[".go"]=" "
[".gz"]=" "
[".gvimrc"]=" "
[".hex"]=" "
[".h"]=" "
[".hpp"]=" "
[".hs"]=" "
[".htm"]=" "
[".html"]=" "
[".ini"]=" "
[".inputrc"]=" "
[".ipynb"]=" "
[".jad"]=" "
[".java"]=" "
[".jar"]=" "
[".jpeg"]=" "
[".jpg"]=" "
[".js"]=" "
[".json"]=" "
[".kt"]=" "
[".kts"]=" "
[".latex"]=" "
["LICENSE"]=" "
[".log"]=" "
[".lua"]=" "
[".lz"]=" "
[".lrz"]=" "
[".md"]=" "
[".mk"]=" "
["Makefile"]=" "
[".make"]=" "
[".mk"]=" "
[".mp3"]=" "
[".mp4"]=" "
[".org"]=" "
[".otf"]=" "
[".pdf"]=" "
[".patch"]=" "
[".perl"]=" "
[".php"]=" "
[".pl"]=" "
[".png"]=" "
[".ppt"]=" "
[".pptx"]=" "
[".ps1"]=" "
[".ps1d"]=" "
[".py"]=" "
[".python_history"]=" "
[".r"]=" "
[".r"]=" "
[".ru"]=" "
[".rar"]=" "
[".rdata"]=" "
[".rds"]=" "
[".rlib"]=" "
[".rmd"]=" "
[".rmd"]=" "
[".sass"]=" "
[".scss"]=" "
[".scala"]=" "
[".sh"]=" "
[".sql"]=" "
[".sv"]=" "
[".svg"]=" "
[".swift"]=" "
[".tar"]=" "
[".taz"]=" "
[".tbz"]=" "
[".tbz2"]=" "
[".tgz"]=" "
[".tex"]=" "
[".tcl"]=" "
[".toml"]=" "
[".ts"]=" "
[".ttf"]=" "
[".txt"]=" "
[".tz"]=" "
[".tzo"]=" "
[".txz"]=" "
[".v"]=" "
[".vhd"]=" "
[".vhdl"]=" "
[".vim"]=" "
[".viminfo"]=" "
[".vimrc"]=" "
[".xul"]=" "
[".woff"]=" "
[".woff2"]=" "
[".xml"]=" "
[".xhtml"]=" "
[".xls"]=" "
[".xlsx"]=" "
[".xz"]=" "
[".yml"]=" "
[".yaml"]=" "
[".zip"]=" "
[".zsh"]=" "
[".zshrc"]=" "
[".zst"]=" "
)
# Define icons and colors for specific directory names
declare -A directory_icons=(
["Pictures"]="\033[1;96m "
["Downloads"]="\033[1;96m "
[".git"]="\033[1;31m "
[".ssh"]="\033[1;96m "
["Music"]="\033[1;96m "
["Desktop"]="\033[1;96m "
[".vscode"]="\033[0;35m \033[1m"
[".config"]="\033[1;96m "
["config"]="\033[1;96m "
["configs"]="\033[1;96m "
["bin"]="\033[1;96m "
["github"]="\033[1;37m "
["Github"]="\033[1;37m "
[".github"]="\033[1;37m "
["GitHub"]="\033[1;37m "
["Videos"]="\033[1;96m "
[".cache"]="\033[1;96m "
)
# Define icons for different file types
# ... (your icon definitions)
# Define icons and colors for specific directory names
# ... (your directory_icons definitions)
# Default icon for files with unknown extensions
default_icon="\033[0;37m \033[0m"
columns=3
padding=24
show_hidden=false # Default behavior is to hide hidden files
# Parse command-line options
while getopts "ac:" opt; do
case $opt in
a)
show_hidden=true # Set the flag to show hidden files
;;
c)
columns=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
# Adjust padding based on the number of columns
if ((columns == 4)); then
padding=25
elif ((columns == 2)); then
padding=40
elif ((columns == 5)); then
padding=23
else
padding=$((35 / 3 * columns - 13))
fi
done
# Function to format output in columns
format_columns() {
local count=0
for item in "${items[@]}"; do
local name="${item%%|*}"
local type="${item#*|}"
local icon="${icons[$type]}"
if [[ -z $icon ]]; then
icon="$default_icon"
fi
local color="\033[0m" # Default color
local min_length=10 # Minimum length to ensure space for ".." and extension
local max_length=$((padding - 3)) # Leaving space for ".." and file extension
if (( ${#name} > max_length )); then
local basename="${name%.*}" # Extracting the filename without extension
local extension="${name##*.}" # Extracting the file extension
local middle=".."
local extension_length=${#extension}
# Adjust the max_length to accommodate the beginning of the filename
local available_length=$((max_length - extension_length - ${#middle}))
if (( available_length < min_length )); then
# If even the beginning is too long, truncate the basename
basename="${basename:0:$((min_length - available_length))}"
else
# Truncate the end of the basename to fit the available length
basename="${basename:0:$available_length}"
fi
# Concatenate the truncated basename with ".." and the extension
name="$basename$middle.$extension"
fi
# Define color based on file type
case "$type" in
folder)
color="\033[1;96m" # Default folder color
# Check if a specific icon and color are defined for the directory name
if [[ -v directory_icons[$name] ]]; then
icon="${directory_icons[$name]}"
color="\033[1;33m" # Custom folder color
fi
;;
.txt) color="\033[0;33m";;
.sh) color="\033[0;32m";;
# ... (other file type colors)
esac
# Add padding and display file/folder name with icon
printf "%b%-*s" "$color$icon" "$padding" "$name"
((count++))
if ((count % columns == 0)); then
printf "\n"
fi
done
# Add a newline if there are remaining items
if ((count % columns != 0)); then
printf "\n"
fi
}
# Get list of files and folders in the current directory
directories=()
files=()
dotfolders=()
dotfiles=()
while IFS= read -r -d $'\0' item; do
# Check if item is a directory or file
if [[ -d "$item" ]]; then
name="${item##*/}"
if [[ $name == .* ]] && ! $show_hidden; then
continue # Skip hidden folders if the flag is not set
fi
if [[ $name == .* ]]; then
dotfolders+=("${item:2}|folder") # Remove leading '/'
else
directories+=("${item:2}|folder") # Remove leading '/'
fi
else
name="${item##*/}"
extension="${name##*.}"
if [[ $name == .* ]] && ! $show_hidden; then
continue # Skip hidden files if the flag is not set
fi
if [[ $name == .* ]]; then
dotfiles+=("${item:2}|.$extension") # Remove leading '/'
else
files+=("${item:2}|.$extension") # Remove leading '/'
fi
fi
done < <(find . -maxdepth 1 ! -path . -print0 | LC_ALL=C sort -z)
# Concatenate directories, files, dotfolders, and dotfiles arrays
items=("${directories[@]}" "${dotfolders[@]}" "${files[@]}" "${dotfiles[@]}")
# Format and display the items in columns
format_columns