-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_aliases
117 lines (109 loc) · 3.07 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
# alias to allow source refresh regardless of shell
if [ "$SHELL" = "/bin/zsh" ];then
alias refresh="source ~/.zshrc"
elif [ "$SHELL" = "/bin/bash" ];then
alias refresh="source ~/.bash_profile"
fi
# automatically expand all aliases
alias -g '$= '
# change sudo based on your mood :sunglasses:
alias please="sudo "
alias fucking="sudo "
# may be more verbose, but sometimes full sentences are cool :sunglasses:
alias copy="cp -R"
alias move="mv"
alias remove="rm -r"
# launches vim and updates file-extension to specific common types
edit() {
if [ -z $2 ]; then
vim $1
elif [ "$1" = "python" ]; then
vim $2.py
elif [ "$1" = "markdown" ]; then
vim $2.md
elif [ "$1" = "json" ]; then
vim $2.json
elif [ "$1" = "yaml" ]; then
vim $2.yaml
else
echo "Unable to interpret file type `$1`"
fi
}
# bunch of colloqiually typed `ls` functions that more simply allow you to
# filter on the type of files or folders being returned
list() {
if [ -z $1 ]; then
# default behavior of list that's being aliased
ls -lhG $2
elif [ "$1" = "all" ]; then
# if `all` then show both hidden and regular files/folders
ls -lahG $2
elif [ "$1" = "folders" ]; then
# folders filters the output of list to folders only
# handles instances when a folder pattern is and is not passed
if [ -z $2 ]; then
ls -ldG */
else
ls -ldG $2/*/
fi
elif [ "$1" = "files" ]; then
# files filters the output of list to files only
# handles instances when a file pattern is and is not passed
if [ -z $2 ]; then
ls -lhpG | grep -v /
else
ls -lhpG $2 | grep -v /
fi
elif [ "$1" = "hidden" ]; then
# hidden filters the output of list to hidden files/folders only
# handles instances when a file/folder pattern is and is not passed
if [ -z $2 ]; then
ls -lahdG .*
elif [ "$2" = "files" ]; then
if [ -z $3 ]; then
ls -lahpdG .* | grep -v '^.*/$'
else
ls -lahpdG $3/.* | grep -v '^.*/$'
fi
elif [ "$2" = "folders" ]; then
if [ -z $3 ]; then
ls -lahdG .*/
else
ls -lahdG $3/.*/
fi
else
ls -lahdG $2/.*
fi
else
# this is an extension of the first instance (i.e. default alias) but
# when a file/folder pattern is passed by the user
if [ -z $2 ]; then
ls -lhG $1
else
echo "Unable to interpret command `list $1 $2`"
fi
fi
}
# create a new file or folder but don't necessarily fill them
new() {
if [ "$1" = "file" ]; then
touch $2
elif [ "$1" = "folder" ]; then
mkdir $2
else
echo "Unable to interpret command `new $1`"
return 1
fi
}
file-exists() {
if [ -f "$1" ]; then
return 0
fi
return 1
}
folder-exists() {
if [ -d "$1" ]; then
return 0
fi
return 1
}