-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls_ft.sh
161 lines (138 loc) · 5.88 KB
/
ls_ft.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
# ############################################################################ #
# ls_ft BEGIN #
# ############################################################################ #
# ⚠ Dependencies: eza, sed #
# ---------------------------------------------------------------------------- #
# From current directory; lists content of current dir #
# Options: lsft, #
# ---------------------------------------------------------------------------- #
# This script is a collection of 4 main functionalities: #
# ---------------------------------------------------------------------------- #
# list_specific_file_type_eza #
# list_files_sort_extension #
# list_files_sort_extension_hidden #
# list_files_and_folders_sort_by_extensions #
# ---------------------------------------------------------------------------- #
# Main aliases are listed below along with sets of alternative aliases: #
# ############################################################################ #
# Main aliases
alias lsft="list_specific_file_type_eza" # list files by extension, requires an argument. For example: lsft .txt
alias sbft="list_files_sort_extension" # Sort by file type, also requires argument
alias lsfth="list_files_sort_extension_hidden" #Lits only files by extension including hidden files, requires argument.
alias lsfta="list_files_and_folders_sort_by_extensions" #require arguments
# Lists files by extension
alias lsfiles="list_specific_file_type_eza"
alias lsftype="list_specific_file_type_eza"
alias lsfiletype="list_specific_file_type_eza"
alias filetype="list_specific_file_type_eza"
alias ft="list_specific_file_type_eza"
alias lst="list_specific_file_type_eza"
alias lstype="list_specific_file_type_eza"
# List only files, sort by extension
alias sortbytype="list_files_sort_extension"
alias sft="list_files_sort_extension"
alias sftype="list_files_sort_extension"
alias sftype="list_files_sort_extension"
alias lstype="list_files_sort_extension"
# List only files including hidden files, sort by extension
alias lstypeh="list_files_sort_extension_hidden"
# List files and folders and sort files by extensions
alias sortall="list_files_and_folders_sort_by_extensions"
# TODO: Add function that counts the total ammount of files of specific file
# type, and 2). Adds an appropriate icon with proper formattingo. And 3). A
# informational message For more options do -f -a -b -c etc.
# Formatting function as empty string is outputtet as blank line
lsformat(){
echo ""
}
# Informational message at the end of lsf (List Files)
lsfecho() {
echo -e "\n\033[1;37m \033[38;5;250m Use \033[1;32mlsfa\033[38;5;250m to see hidden files.\033[0m\n"
}
# Informational message at the end of lsfh
lsfhidden(){
echo -e "\n\033[1;37m \033[38;5;250m Use \033[1;32mlsfh\033[38;5;250m to \033[1;4monly\033[0m hidden files.\033[0m\n"
}
# add_icons_to_files() {
# eza_output=$(eza -1 --icons -a --only-files | sed -n '/^\./p')
#
# while IFS= read -r file; do
# # Use eza's output to add the correct icon to each file
# # eza automatically displays icons based on file types, so we can capture the icon and filename
# icon=$(echo "$file" | cut -d ' ' -f1) # Capture the icon
# filename=$(echo "$file" | cut -d ' ' -f2-) # Capture the filename
# echo "$icon $filename" # Display the icon along with the filename
# done <<< "$eza_output"
# }
# TODO: Write custom icon-set for each file type similar to eza
add_icons_to_files() {
eza -1 --icons -a --only-files | sed -n '/^\./p' | while IFS= read -r line; do
echo "📄 $line" # Add a custom emoji or text before each file
done
}
# List specific file types. E.g., lsfiles .txtlsfh
list_specific_file_type_eza() {
if [[ -z "$1" ]]; then
echo "Usage: listfiles <extension>"
return 1
fi
# Remove leading dot if user includes it (normalize input)
ext="${1#.}"
# Check if any file has the given extension
# Zsh globbing to find matching files
matches=(*."$ext"(.N))
if [[ ${#matches[@]} -eq 0 ]]; then
echo "No files found with .$ext extension."
return 1
fi
# Use eza if installed, otherwise fallback to ls
if command -v eza &>/dev/null; then
eza --icons --group-directories-first *."$ext"
else
ls -lh *."$ext"
fi
}
# List only files (not folders nor files in folders) in current directory
list_files_sort_extension() {
# Use eza if installed
if command -v eza &>/dev/null; then
eza --icons --only-files --color=always --sort=ext
else
# Fallback to ls + sort
ls -lh --color=always | sort -k9 -t.
fi
}
list_files_sort_extension_hidden() {
# Use eza if installed
if command -v eza &>/dev/null; then
eza --icons --only-files --hidden --color=always --sort=ext
else
# Fallback to ls + sort
ls -lh --color=always | sort -k9 -t.
fi
}
list_files_and_folders_sort_by_extensions() {
# Use eza if installed
if command -v eza &>/dev/null; then
eza --icons --group-directories-first --color=always --sort=ext
else
# Fallback to ls + sort
ls -lh --color=always | sort -k9 -t.
fi
}
# lsfile() {
# if [[ -z "$1" ]]; then
# echo "Usage: listfiles <pattern>"
# return 1
# fi
# printf "%s\n" *"$1"*
# }
# alias lsfall='list_all_files_in_current_directory'
# alias lsfilesall='list_all_files_in_current_directory'
# list_all_files_in_current_directory() {
# if [[ -z "$1" ]]; then
# echo "Usage: listfiles <pattern>"
# return 1
# fi
# eza --ignore-glob="!*$1*" --icons --only-files
# }