-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_aliases
254 lines (225 loc) · 6.79 KB
/
.bash_aliases
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
# general
# TODO: Disable Ctrl-Q and S if possible too (avoid hang)
set -o ignoreeof # disable closing terminal on ctrl-d
# fzf
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
export FZF_DEFAULT_COMMAND="rg --files --hidden -g '!.git'"
if [ -f ~/.config/nvim/autoload/plugged/fzf/shell/key-bindings.bash ]; then
source ~/.config/nvim/autoload/plugged/fzf/shell/key-bindings.bash
source ~/.config/nvim/autoload/plugged/fzf/shell/completion.bash
fi
# git
source /usr/share/bash-completion/completions/git
alias gst="git status -uno"
alias branch="git rev-parse --abbrev-ref HEAD"
alias branches="git branch --sort=committerdate"
alias gl="git log --pretty=oneline --abbrev-commit"
gitdate() {
git log --after="$1 00:00" --before="$1 23:59"
}
gitrbi() {
git rebase -i HEAD~10
}
# convert video to compressed mp4 and webm
convertvideo()
{
if [ -Z $1 ]; then
echo "convertvideo <video_file> <output_name>"
return 0
fi
local vidfile=$1
local outputname=$2
ffmpeg -i $vidfile -vcodec libx264 -f mp4 -crf 28 -preset slow -an "${outputname}.mp4"
ffmpeg -i $vidfile -f webm -vcodec libvpx-vp9 -vb 1024k -an "${outputname}.webm"
}
# unsorted
alias c="clear"
alias fn="find -name"
alias ls="ls --color=auto"
alias lsize="du -h --max-depth=1 | sort -h"
alias week="date +'%U'"
alias editba="vim $HOME/.bash_aliases"
alias srcba=". $HOME/.bash_aliases"
alias cdd="cd $HOME/documents/"
alias vimsession="vim -c \"cabbrev q <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'close' : 'q')<CR>\""
alias cutvideo="losslesscut"
alias startgnome="startx ~/.xinitrc gnome"
alias externalip="wget http://ipinfo.io/ip -qO -"
# xargs trim the white space
alias internalip="hostname -I | xargs"
alias vim="nvim"
alias vimdiff='nvim -d'
alias editbootstrap="vim $HOME/.config/yadm/bootstrap"
alias editi3="vim $HOME/.config/i3/config"
alias editalacritty="vim $HOME/.config/alacritty/alacritty.yml"
alias editvim="vim $HOME/.config/nvim/init.vim"
alias grepcolor="grep -a --color=always"
alias lsmodified="ls -lahtr"
alias tree="tree -F --dirsfirst --noreport -C | sed -e 's/[├──└│]/ /g'"
alias 7ze="7z e"
alias l="ls -larth" # By modified date in reversed order
# Commands for safer removal of files
alias rmconfirm="rm -i"
function dryrm()
{
find . -depth -name "$1" -print
}
# loop a command X times
# loop_cmd <n times> "<command>" <time s> <args...>
# e.g. loop_cmd 100 "echo 'hej'" <0.4s>
loop_cmd() {
local times=$1
local cmd=$2
local sleeptime=$3
if [ -z "$times" ] || [ -z "$cmd" ] || [ -z "$sleeptime" ]; then
echo "Must supply times, cmd, sleeptime arguments"
return 1
fi
for i in `seq 1 $times`; do
echo "----$i/$times----";
eval $cmd || break;
sleep $sleeptime
done
}
# print uniq lines from file
uniqlines()
{
# Uniq lines except blank lines
# https://stackoverflow.com/questions/11532157/remove-duplicate-lines-without-sorting
cat $1 | awk '!/./ || !seen[$0]++'
# Or this?
# cat $1 | awk '!seen[$0]++'
}
trynvchad()
{
sudo docker run -w /root -it --rm alpine:edge sh -uelic '
apk add git nodejs neovim ripgrep alpine-sdk --update
git clone https://github.com/NvChad/NvChad ~/.config/nvim
nvim -c "autocmd User PackerComplete quitall" -c "PackerSync"
nvim
'
}
new_bashscript()
{
local scriptname=$1
if [ -z "$scriptname" ];
then
echo "Must supply script name"
return 1
fi
if [ -f "$scriptname" ];
then
echo "$scriptname already exists"
return 1
fi
echo '#!/bin/bash' > $scriptname && chmod u+x $scriptname
vim $scriptname
}
function dumphex()
{
local filename="$1"
xxd "$filename" > "$filename.hex"
}
function restorehex()
{
local filename="$1"
xxd -r "$filename" > "$filename.restored"
}
function canon_m50_webcam()
{
# Stream from Canon m50
# https://www.crackedthecode.co/how-to-use-your-dslr-as-a-webcam-in-linux/
sudo modprobe v4l2loopback
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
}
function mp4_to_mov()
{
local inputvid="$1"
local outputvid="$2"
if ! [[ -f "$inputvid" ]]; then
echo "Input video doesn't exist"
echo "mp4_to_mov <input.mp4> <output.mov>"
return 1
fi
if [[ -f "$outputvid" ]]; then
echo "Output video already exists"
echo "mp4_to_mov <input.mp4> <output.mov>"
return 1
fi
if [[ -z "$outputvid" ]]; then
echo "Must supply output video name"
echo "mp4_to_mov <input.mp4> <output.mov>"
return 1
fi
ffmpeg -i "$inputvid" -vcodec mjpeg -q:v 2 -acodec pcm_s16be -q:a 0 -f mov "$outputvid";
}
function all_mp4_to_mov()
{
for file in *.MP4 *.mp4; do
[ -f "$file" ] || break
local filename="${file%.*}"
if [ -f "$filename.mov" ]; then
echo ".mov exist already"
else
mp4_to_mov $file "$filename.mov"
fi
done
}
function mov_to_mp4()
{
local inputvid="$1"
local outputvid="$2"
if ! [[ -f "$inputvid" ]]; then
echo "Input video doesn't exist"
echo "mov_to_mp4 <input.mov> <output.mp4>"
return 1
fi
if [[ -f "$outputvid" ]]; then
echo "Output video already exists"
echo "mov_to_mp4 <input.mov> <output.mp4>"
return 1
fi
if [[ -z "$outputvid" ]]; then
echo "Must supply output video name"
echo "mov_to_mp4 <input.mov> <output.mp4>"
return 1
fi
ffmpeg -i "$inputvid" -vcodec h264 -acodec aac "$outputvid"
}
function load_nvm()
{
# This is slow, so don't load this automatically
# Must run load_nvm before using nvm (e.g. nvm use 16.0)
if [ -d $HOME/.nvm ]; then
export NVM_DIR="$HOME/.nvm"
echo "Load nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
fi
}
function extract() {
local package=$1
if [ -f $package ] ; then
case $package in
*.tar.bz2) tar xvjf $package ;;
*.tar.gz) tar xvzf $package ;;
*.tar.xz) tar xf $package ;;
*.bz2) bunzip2 $package ;;
*.rar) unrar x $package ;;
*.gz) gunzip $package ;;
*.tar) tar xvf $package ;;
*.tbz2) tar xvjf $package ;;
*.tgz) tar xvzf $package ;;
*.zip) unzip $package ;;
*.Z) uncompress $package ;;
*.7z) 7z x $package ;;
*) echo "don't know how to extract '$package'..." ;;
esac
else
echo "'$package' is not a valid file!"
fi
}
# Include host-specific aliases
if [ -f $HOME/.host_aliases ]; then
source $HOME/.host_aliases
fi