-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_function
97 lines (87 loc) · 2.42 KB
/
.bash_function
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
#####################################################
#### Functions #######
#####################################################
#
# Create and initialize a git repo
#
function ginit {
mkdir $1
cd $1
git init
}
#
# Display to the terminal
#
function osd {
osd_cat --align=center --pos=middle --outline=1 \
--outlinecolour=#000000 --delay=3 --font="$font" \
"$@"
}
# Killlist
function killps {
ps aux | grep $1 | grep -v grep | awk {'print $2'} | xargs kill -9 2> /dev/null
}
# Makes directory then moves into it
function mkcdr {
mkdir -p -v $1
cd $1
}
# Easy extract
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar 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
}
# A frequent source of complaint from cat
# is that I've just asked it to cat a directory.
# If I have, just DWIM and do it happily.
function catorls () {
if [ -d $1 ];
then
ls -l $1
else
cat $1
fi
}
alias cat="catorls"
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
# the `.git` directory, listing directories first. The output gets piped into
# `less` with options to preserve color and line numbers, unless the output is
# small enough for one screen.
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}
# Get a character’s Unicode code point
function codepoint() {
perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))";
# print a newline unless we’re piping the output to another program
if [ -t 1 ]; then
echo ""; # newline
fi;
}
# Decode \x{ABCD}-style Unicode escape sequences
function unidecode() {
perl -e "binmode(STDOUT, ':utf8'); print \"$@\"";
# print a newline unless we’re piping the output to another program
if [ -t 1 ]; then
echo ""; # newline
fi;
}
function big() {
find /home/cgandevia -type f -size +"$@"k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
}