-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_functions
173 lines (151 loc) · 3.86 KB
/
.bash_functions
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
#!/bin/bash
# change directory and ls
function cl() {
DIR="$*";
# if no DIR given, go home
if [ $# -lt 1 ]; then
DIR=$HOME;
fi;
builtin cd "${DIR}" && exa
}
function mkcd() {
DIR="$*";
if [ $# -lt 1 ]; then
echo -e "\e[31mdirectory field can't be empty\n\e[0mmkcd <directory>"
return;
fi;
mkdir "${DIR}" && cd "${DIR}"
}
function gitcheat() {
DATE="$1"
if [ "$DATE" ]; then
# Tue Apr 12 15:23:10 2022 +0545
export GIT_COMMITTER_DATE="$DATE" && git commit --amend --no-edit --date "$DATE"
return;
fi;
echo -e "Provide the date in format:\nTue Apr 12 15:23:10 2022 +0545\n"
}
function pubip() {
IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
if [ "$IP" ]; then
echo "${IP} is your public IP address";
return;
fi;
echo -e "Couldn't connect to internet";
}
function capturePic() {
ffmpeg -f video4linux2 -s vga -i /dev/video0 -v 0 -vframes 1 /tmp/termCap1.jpg
}
function copy() {
copyq copy "$1" && copyq add "$1";
}
function clip() {
local input="$(< /dev/stdin)"
if [ -z "$input" ];
then
copy "$1"
else
copy "$input"
fi
}
function trim() {
local input="$(< /dev/stdin)"
if [ -z "$input" ];
then
echo "only stdin is supported"
else
awk '{$1=$1};1' <<< "$input"
fi
}
function pdflower() {
local FILE="$1"
b gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile="resized_$FILE" "$FILE"
}
function tnew() {
tmux new -s `pwd | sed 's/.*\///g'`
}
function topen() {
local tmux_session=`tmux ls | awk -F: '{print $1}'`
if [ "$tmux_session" ];
then
local selected_session=`echo "$tmux_session" | fzf`
if [ "$selected_session" ];
then
tmux attach -t "$selected_session"
fi
fi
}
function ttopen() {
local session=$*;
if [ "$session" ]; then
tmux new-session -d -s "$session"
tmux switch-client -t "$session"
else
local tmux_session=`tmux ls | awk -F: '{print $1}'`
if [ "$tmux_session" ];
then
local selected_session=`echo "$tmux_session" | fzf`
if [ "$selected_session" ];
then
tmux new-session -d -s "$selected_session"
tmux switch-client -t "$selected_session"
fi
fi
fi
}
function gs() {
git stash push -m "$*"
}
function gsa() {
git stash apply stash^{/"$1"}
}
function music() {
song=$1
volume=`[ $2 ] && echo "$2" || echo 50`;
youtube-dl -f bestaudio ytsearch:"$song" -o - 2>/dev/null | ffplay -nodisp -autoexit -volume $volume -i - &>/dev/null
}
function v() {
local currentDirectory=`pwd`
local vim_sessions=`/usr/bin/ls "$currentDirectory"| grep "\.vim"`
local session_count=`echo $vim_sessions | wc -l`
if [[ $session_count -eq 0 || -z "$vim_sessions" ]]; then
nvim $*;
return;
elif [[ $session_count -eq 1 ]]; then
nvim -S $vim_sessions $*;
return;
else
local selected_session=`echo $vim_sessions | fzf --reverse`
nvim -S $selected_session $*;
return;
fi
}
function b() {
# run original bash command instead of alias
local command="$@"
bash -c "$command"
}
function addToPath() {
if [ -d "$1" ]; then
if [[ "$PATH" != *"$1"* ]]; then
export PATH=$PATH:$1;
return;
fi;
echo "Path already exists";
fi
}
function convertProxyUrlToHttp() {
# conver domain:port:username:password to http://username:password@domain:port
local proxyUrl="$1"
local domain=`echo "$proxyUrl" | awk -F: '{print $1}'`
local port=`echo "$proxyUrl" | awk -F: '{print $2}'`
local username=`echo "$proxyUrl" | awk -F: '{print $3}'`
local password=`echo "$proxyUrl" | awk -F: '{print $4}'`
if [ -z "$username" ]; then
echo "export http_proxy=http://$domain:$port"
echo "export https_proxy=http://$domain:$port"
else
echo "export http_proxy=http://$username:$password@$domain:$port"
echo "export https_proxy=http://$username:$password@$domain:$port"
fi
}