-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_functions
125 lines (111 loc) · 2.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
# -----------------
# --- FUNCTIONS ---
# -----------------
# hard reset git repo
function rr() {
git branch | grep -q "main"
if [ $? -eq 0 ]; then
GitSource="main"
else
GitSource="master"
fi
COL1='\e[38;5;215m'
COL2='\e[38;5;223m'
CLEARCOL='\e[38;5;240m'
echo -e "${COL1}# - - - - - - - - - - - - - - - -${CLEARCOL}"
echo -e "${COL1}# - GIT CLEANUP : FETCH & RESET -${CLEARCOL}"
echo -e "${COL1}# - - - - - - - - - - - - - - - -${CLEARCOL}"
echo
echo -e "${COL1}# fetch data from origin${CLEARCOL}"
echo -e "${COL2}$ git fetch origin${CLEARCOL}"
git fetch origin
echo
echo -e "${COL1}# do a hard reset${CLEARCOL}"
echo -e "${COL2}$ git reset --hard origin/$GitSource${CLEARCOL}"
git reset --hard origin/$GitSource
echo
echo -e "${COL1}# pull current data${CLEARCOL}"
echo -e "${COL2}$ git pull${CLEARCOL}"
git pull
}
# Change directory & list files
function cl {
DIR="$*";
# if no DIR given, go home
if [ $# -lt 1 ]; then
DIR=$HOME;
fi;
cd "${DIR}" && \
# use your preferred ls command
ls
}
# Make directory & enter it
function mkcd {
mkdir -p $1
cd $1
}
# Make directory, move files & enter it
function mvd {
mkdir -p ${@[$#]}
mv $*
cd ${@[$#]}
}
# Make directory, copy files & enter it
function cpd {
mkdir -p ${@[$#]}
cp -r $*
cd ${@[$#]}
}
# Move up folders
# e.g:
# up -> cd ../
# up 2 -> cd ../../
# up 3 -> cd ../../../
function up {
local count=$1
if [ -z "${count}" ]; then
count=1
fi
local path=""
for i in $(seq 1 ${count}); do
path="${path}../"
done
path=$(echo $path | sed 's/^\///')
cd $path
}
# Decompress just about any compressed file format
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
return 1
else
for n in $@
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}