-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshell_utils.fish
More file actions
175 lines (140 loc) · 4.87 KB
/
shell_utils.fish
File metadata and controls
175 lines (140 loc) · 4.87 KB
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
# shell_utils.fish
# If not an interactive shell, do nothing.
# This prevents errors with scp and sftp.
status --is-interactive; or exit
set shell_utils ~/.shell_utils
set shell_utils_users ~/.local/shell_utils
set shell_utils_configs ~/.shell_utils_configs
if set -q TERMUX_VERSION
set -g USER (id -un)
end
# Path to your shell_utils installation.
if not test -d "$shell_utils"
git clone https://github.com/felipefacundes/shell_utils "$shell_utils"
end
# Path to your shell_utils configs
if not test -d "$shell_utils_configs"
mkdir -p "$shell_utils_configs"
end
# Loops through all .fish files in the source directory and its subdirectories
function sourced
set -l source_dir $argv[1]
set -l output_file "$source_dir.fish"
# If the directory does not exist, remove file and exit
if not test -d "$source_dir"
if test -f "$output_file"
rm -f "$output_file"
end
return 0
end
# Find .fish files
set -l fish_files (find "$source_dir" -name "*.fish" -type f 2>/dev/null)
if test (count $fish_files) -gt 0
# Create file with sources
for file in $fish_files
echo "source \"$file\""
end > "$output_file"
return 0
else
# Remove empty file if there are no .fish files
if test -f "$output_file"
rm -f "$output_file"
end
return
end
end
# Priority - What should be started before
set source_path priority
sourced "$shell_utils/$source_path"
if test -f "$shell_utils/$source_path.fish"
source "$shell_utils/$source_path.fish"
end
if not test -d "$shell_utils_users/$source_path"
mkdir -p "$shell_utils_users/$source_path"
end
sourced "$shell_utils_users/$source_path"
if test -f "$shell_utils_users/$source_path.fish"
source "$shell_utils_users/$source_path.fish"
end
########################################
############# MY VARIABLES #############
set source_path variables
sourced "$shell_utils/$source_path"
if test -f "$shell_utils/$source_path.fish"
source "$shell_utils/$source_path.fish"
end
if not test -d "$shell_utils_users/$source_path"
mkdir -p "$shell_utils_users/$source_path"
end
sourced "$shell_utils_users/$source_path"
if test -f "$shell_utils_users/$source_path.fish"
source "$shell_utils_users/$source_path.fish"
end
########################################
############# MY FUNCTIONS #############
set source_path functions
sourced "$shell_utils/$source_path"
if test -f "$shell_utils/$source_path.fish"
source "$shell_utils/$source_path.fish"
end
if not test -d "$shell_utils_users/$source_path"
mkdir -p "$shell_utils_users/$source_path"
end
sourced "$shell_utils_users/$source_path"
if test -f "$shell_utils_users/$source_path.fish"
source "$shell_utils_users/$source_path.fish"
end
########################################
############### ALIASES ###############
# Example aliases:
# alias bashconfig="vim ~/.bashrc"
# alias zshconfig="vim ~/.zshrc"
set source_path aliases
sourced "$shell_utils/$source_path"
if test -f "$shell_utils/$source_path.fish"
source "$shell_utils/$source_path.fish"
end
if not test -d "$shell_utils_users/$source_path"
mkdir -p "$shell_utils_users/$source_path"
end
sourced "$shell_utils_users/$source_path"
if test -f "$shell_utils_users/$source_path.fish"
source "$shell_utils_users/$source_path.fish"
end
########################################
### USER SCRIPTS / HELPS / MARKDOWNS ###
if not test -d "$shell_utils_users/scripts/helps/markdowns"
mkdir -p "$shell_utils_users/scripts/helps/markdowns"
end
if not test -d "$shell_utils_users/scripts/utils"
mkdir -p "$shell_utils_users/scripts/utils"
end
##### History
if not test -f ~/.local/share/fish/fish_history
touch ~/.local/share/fish/fish_history
end
##### SECURITY - Note: Fish doesn't use these history files, but we'll keep for compatibility
# These sed commands are kept for bash/zsh users but won't affect Fish
sed -i 's#cmd: rm #cmd: rm_locked #g' ~/.local/share/fish/fish_history
sed -i 's#cmd: sudo rm #cmd: rm_locked #g' ~/.local/share/fish/fish_history
sed -i 's#cmd: doas rm #cmd: rm_locked #g' ~/.local/share/fish/fish_history
sed -i 's#cmd: mv #cmd: mv_locked #g' ~/.local/share/fish/fish_history
sed -i 's#cmd: sudo mv #cmd: mv_locked #g' ~/.local/share/fish/fish_history
sed -i 's#cmd: doas mv #cmd: mv_locked #g' ~/.local/share/fish/fish_history
sed -i 's|/dev/sd[abcdefghij][123456789]|/dev/sdX|g' ~/.local/share/fish/fish_history
sed -i 's|/dev/sd[abcdefghij]|/dev/sdX|g' ~/.local/share/fish/fish_history
# Load ASCII Theme Art
"$shell_utils/scripts/ascii-theme-select"
# SHELL_UTILS AUTO UPDATE
"$shell_utils/scripts/shell-utils-update"
########################################
set -e shell_utils_configs
set -e shell_utils_users
set -e shell_utils
set -e source_file
set -e source_path
# Clean up functions
functions -e sourced
if set -q TERMUX_VERSION
cd /sdcard; or true
end