-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_shell.functions
More file actions
216 lines (187 loc) · 3.76 KB
/
Copy path_shell.functions
File metadata and controls
216 lines (187 loc) · 3.76 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
function brewSourceIfPresent
{
if hash brew 2>/dev/null
then
file="$(brew --prefix)/$1"
if [ -s "$file" ]
then
echo "sourcing shared brew file $file"
source "$file"
fi
fi
}
function SetenvDir
{
eval "$1='$2' export $1";
if [ ! -d $2 ]
then
$ECHO "$0: SetenvDir: warning: $2 does not exist"
fi
}
function Setenv
{
eval "$1='$2' export $1";
}
function Addpath
{
PATH=$PATH:$1 export PATH
if [ ! -d $1 ]
then
$ECHO "$0: Addpath: warning: $1 does not exist"
fi
}
function AddpathIfPresent
{
if [ -d $1 ]
then
PATH=$PATH:$1 export PATH
fi
}
function Addlpath
{
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$1 export LD_LIBRARY_PATH
if [ ! -d $1 ]
then
$ECHO "$0: Addlpath: warning: $1 does not exist"
fi
}
function AddClassPath
{
CLASSPATH=$CLASSPATH:$1 export CLASSPATH
if [ ! -f $1 ]
then
$ECHO "$0: AddClassPath: warning: $1 does not exist"
fi
}
function Addman
{
MANPATH=$MANPATH:$1 export MANPATH
if [ ! -d $1 ]
then
$ECHO "$0: Addman: warning: $1 does not exist"
fi
}
function newf
{
ls -lthF "$@" | head -25
}
function mcd
{
mkdir -p $1
cd $1
}
function scd
{
### alias scd="set mydir=`pwd`;cd `echo $mydir | sed "s/\!:1/\!:2/"`"### alias mcd="mkdir -p \!* ; cd \!*"
mydir=$(pwd)
newdir=$(echo $mydir | sed "s/$1/$2/")
echo cd $newdir
cd "$newdir"
}
# http://transfer.sh
#
function transfer
{
if [ $# -eq 0 ]
then
echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1
fi
tmpfile=$( mktemp -t transferXXX )
if tty -s
then
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile
else
curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile
fi
cat $tmpfile
echo ""
rm -f $tmpfile
}
function usage
{
local total=0
du -sk -- "$1"* 2>/dev/null | sort -nr | awk -F '\t' '
BEGIN {
hum[1]="K"; hum[2]="M"; hum[3]="G"; hum[4]="T";
}
{
sizes[NR]=$1; paths[NR]=$2;
total += $1;
}
END {
for (i = 1; i <= NR; i++) {
size = sizes[i];
unit = 1;
while (size >= 1024 && unit < 4) {
size /= 1024;
unit++;
}
printf "%6.1f%s\t%s\n", size, hum[unit], paths[i];
}
t = total;
tu = 1;
while (t >= 1024 && tu < 4) {
t /= 1024;
tu++;
}
printf "-----------------------------\n";
printf " %6.1f%s\ttotal\n", t, hum[tu];
}'
}
function usageOLD
{
if command -v gsort >/dev/null 2>&1
then
SORT=gsort
else
SORT=cat
fi
du -hcs $1* | $SORT
}
function checkUpToDate
{
local status
local today=$(date "+%d")
local marker=$HOME/.unixEnvStatus
local wrapper=""
# if the marker is older than a day
#
local count=$( (find $marker -mtime 1 | wc -l) 2> /dev/null )
if [ ! -f "$marker" ] || [ ${count} -gt 0 ]
then
cd $UNIX_ENV_DIR
status="Unix Env $(${UNIX_ENV_DIR}/bin/gitstatus.sh)"
cd - > /dev/null
if [ $? -ne 0 ]
then
wrapper="#######################################################\n"
fi
rm $marker
[ -n "$wrapper" ] && echo $wrapper > $marker
echo $status >> $marker
[ -n "$wrapper" ] && echo $wrapper >> $marker
fi
cat $marker
}
# File System JQ
function fsj
{
file="$1"
if [ -f "$file" ]
then
tmpfile=$(mktemp)
jq . "$file" > $tmpfile
if [ $? -eq 0 ]
then
mv $tmpfile "$file"
else
echo "JQ Failed"
fi
fi
}
function pj
{
ping 192.168.1.${1}
}