-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.sh
More file actions
195 lines (169 loc) · 4.38 KB
/
basic.sh
File metadata and controls
195 lines (169 loc) · 4.38 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
echo 'Loaded: basic.sh'
#find strings in folder
alias srch='grep -rniI --exclude-dir={bundles,dist,node_modules,bower_components} . -e' # ex) srch "search term"
srchFilename() {
find . -iname "*$1*"
}
srchFoldername() {
find . -iname "*$1*" -type d
}
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias back='cd $OLDPWD'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ll='ls -al'
alias l='ls -alrt'
m.tail-logsf() {
if [[ "$(uname -s)" == "Linux" ]]; then
tail -vf "$(ls -rt /var/log/ -I 'wtmp*' -I '*.gz' -I 'dpkg*gz' -I 'postgresql' | head -1)"
else
tail -f /var/log/system.log
fi
}
# This handy tool tells you how much space you have left on a drive
alias df='df -h'
#alias du='du -h --max-depth=1'
alias dusort='du -sh * | sort -rn'
m.zip-archive() {
if [ -z "$1" ]; then
echo "Usage: $0 folder_name"
return 1
fi
# $1 destination archive name
zip -r "$1.zip" "$1"
}
# Extract
m.zip-unarchive() {
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "$1 is not a valid file!"
fi
}
alias sudo='sudo '
alias sv='sudo nvim'
# Internet speed test function
m.speedtest() {
speedtest-cli
}
# -a = -rlptgoD; removed -po
# -p, --perms preserve permissions
# -o, --owner preserve owner (super-user only)
# -n --dry-run
# -del --delete-excluded
# --exclude 'file or dir'
# --info=progress2 try if too verbose also remove -v
alias m.cp-rsync='rsync --recursive --links --times --devices --specials --partial --human-readable --progress -v'
alias m.mv-rsync='rsync --recursive --links --times --devices --specials --partial --human-readable --progress -v --remove-source-files'
m.gpg-import() {
echo "Provide a private.key for $1"
gpg --import "$1"
}
m.gpg-encrypt-sign() {
# Check if either --help is called or not enough arguments are provided
if [[ "$1" == "--help" || $# -ne 2 ]]; then
echo "Usage: m.gpg-encrypt-sign <recipient> <file>"
echo ""
echo "Encrypt and sign a file for a specified recipient using GPG."
echo ""
echo "Arguments:"
echo " <recipient> The GPG key ID, email, or user ID of the recipient"
echo " <file> The file you want to encrypt and sign"
return 1
fi
# Encrypt and sign the file
gpg --encrypt --sign -r "$1" "$2"
}
m.gpg-encrypt() {
# Check if either --help is called or if no arguments are provided
if [[ "$1" == "--help" || $# -ne 1 ]]; then
echo "Usage: m.gpg-encrypt <file>"
echo ""
echo "Encrypt a file symmetrically using GPG."
echo ""
echo "Arguments:"
echo " <file> The file you want to encrypt"
return 1
fi
# Encrypt the file symmetrically
gpg --symmetric "$1"
}
m.gpg-decrypt() {
# Check if a file was actually passed
if [[ -z "$1" ]]; then
echo "Usage: m.gpg-decrypt <file.gpg>"
return 1
fi
# Strip the .gpg extension from the file name if it exists
output_file="${1%.gpg}"
# Perform the decryption, specifying the output file
gpg --output "$output_file" --decrypt "$1"
}
m.base64-decode() {
echo -n "$1" | base64 --decode
}
m.base64-encode() {
echo -n "$1" | base64
}
ff() {
m.ff
}
function m.fc() {
local file
file=$(fzf --preview 'bat --style=numbers --color=always --line-range :500 {}')
if [[ $file ]]; then
cat "$file"
echo "$file"
else
echo "cancelled m.ff"
fi
}
function m.fd() {
local dir
dir=$(find ${1:-.} -type d 2>/dev/null | fzf +m) && cd "$dir"
echo "$dir"
ls
}
function m.kill() {
local pid
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]; then
echo "$pid" | xargs kill -"${1:-9}"
fi
}
function m.env() {
local out
out=$(env | fzf)
echo "$(echo "$out" | cut -d= -f2)"
}
function m.source-yaml() {
local file="$1"
if [ -z "$file" ]; then
echo "Usage: source-yaml <file>" >&2
return 1
fi
if [ ! -f "$file" ]; then
echo "source-yaml: file not found: $file" >&2
return 1
fi
eval "$(yq -r 'to_entries | .[] | "export \(.key)=\(.value | @sh)"' "$file")"
}