-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_bash.functions
134 lines (119 loc) · 2.9 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
#!/bin/sh
#--------------------------------------------------------
# User specific functions
#--------------------------------------------------------
# Get an absolute path
# usage: path=$(abs_path $1)
function abs_path {
case $1 in
*/*)
(cd "${1%/*}" &>/dev/null && printf "%s/%s" "$(pwd)" "${1##*/}");;
*)
printf "%s/%s" "$(pwd)" "$1";;
esac
}
# List of all installed Perl modules
function cpan_list {
perl -MExtUtils::Installed -MData::Dumper -e 'my ($inst) = ExtUtils::Installed->new(); print Dumper($inst->modules());'
}
# move file to the Gnome Wastebacket
function del {
#echo $FULLNAME
if [ $1 ]; then
if [ $1 == "--help" ]; then
echo "Usage: delete [path/filename]"
echo "Delete is a safer alternative to rm (remove), as Delete will send your file to the Gnome Wastebasket."
else
cd `dirname $1`
pathname=`pwd`
filename=$1 ##*/
if [ $pathname != "/" ]; then
fullname="$pathname/$filename"
else
fullname="/$filename"
fi
mv $1 ~/.local/share/Trash/files/
timestamp="`date +%Y`-`date +%m`-`date +0`T`date +%X`"
echo -e "[Trash Info]\nPath=$fullname\nDeletionDate=$timestamp" >> ~/.local/share/Trash/info/$filename.trashinfo
fi
else
echo -e "$0: missing operand\nTry '$0 --help' for more information."
fi
}
# Converts png images into eps
function png2eps {
fname=`basename $1 .png`
convert $1 $fname.ps
ps2eps -f --fixps $fname.ps
}
# If file is a TeX file, then run gvim synchronized with srcltx
function gvim {
eval `perl -e '
use File::Basename;
my ($fn, $fp, $fs) = fileparse($ARGV[0], qr:\\.[^.]*:);
if ($fs eq ".tex") { \
print "/usr/local/bin/gvim --servername vimtex $ARGV[0]";
} else { \
print "/usr/local/bin/gvim $ARGV[0]";
}' $1`
}
# Generates a pass
# e.g. pass "gmail.com"
function pass {
echo $1 | md5sum | sed -e 's/0/O/g' | sed -e 's/1/;/g' | sed -e 's/2/@/g' | sed -e 's/4/%/g' | sed -e 's/b/B/g'
}
calc() {
echo "scale=4;${*}" | bc
}
cdl() {
cd "${*}" && ls -l
#cd "$*" && ls -l
}
total() {
# other option
# du -ch "${@}" | grep total
du -sh
}
h() {
echo ${*}
if [ $# -ge 1 ]
then
history | grep "$*"
else
history
fi
}
function myip {
# other option
# ip addr show |grep "inet " |grep -v 127.0.0. |head -1|cut -d" " -f6|cut -d/ -f1
# ip route get 8.8.8.8 | sed -n '/src/{s/.*src *//p;q}'
ip route get 8.8.8.8 | head -1 | sed -E 's/^.*src ([.0-9]*).*/\1/'
}
function top_files() {
if [[ $1 ]]
then
number=$1
else
number=10
fi
find $2 -type f -exec du -Sh {} + | sort -rh | head -n $number
}
function top_dirs() {
if [[ $1 ]]
then
number=$1
else
number=10
fi
du -Sh $2 | sort -rh | head $number
}
function kblayout {
# setxkbmap -query | grep layout | sed -e 's/layout:[[:space:]]*//'
setxkbmap -v | awk -F "+" '/symbols/ {print $2}'
}
function killp {
kill `lsof -t -i:$1`
}
function cviewer {
pygmentize $1 | less -r
}