-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctons.sh
More file actions
executable file
·1259 lines (1078 loc) · 28 KB
/
Copy pathfunctons.sh
File metadata and controls
executable file
·1259 lines (1078 loc) · 28 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# x
,. () {
[[ -f .cd ]] && . .cd
}
,, () {
cde . "$@"
}
# xx
3d () {
3l -d "$@"
}
3l () {
local options_= shifts_=
[[ $1 =~ ^[-]d$ ]] && options_="-d" && shift
[[ $1 =~ ^[0-9]+$ ]] && options_="-L $1" && shifts_=1
[[ $1 =~ ^[-]L$ ]] && options_="$1 $2" && shifts_=2
[[ $options_ ]] || options_="-L 3"
[[ $1 =~ ^[-]P$ ]] && options_="$options_ $1 $2" && shifts_=2
[[ $shifts_ ]] && shift $shifts_
Tree $options_ "$@"
}
arg_dirs () {
local dir_=. arg_= path_= result_=1
for arg_ in "$@"; do
[[ -e "$arg_" ]] || continue
path_=$( readlink -f "$arg_")
[[ -d "$path_" ]] && dir_="$path_"
[[ -f "$path_" ]] && dir_=$(dirname "$path_")
[[ -d "$dir_" ]] && result_=0
[[ -d "$dir_" ]] && echo $dir_
done
return $result_
}
arg_dir () {
[[ -e "$1" ]] || return 1
local path_=$( readlink -f "$1") dir_=
[[ -d "$path_" ]] && echo "$path_" || dirname "$path_"
return 0
}
# xxx
3dt () {
3d | grep -v -e __pycache__ -e egg
}
3dy () {
3dt | grep -v -e test
}
envv () {
env | grep VIRTUAL_ENV= | grep '=.*'
}
vgf () {
edit_source ~/bash/git/functons.sh ~/.gitconfig "$@"
}
vla () {
_edit_locals aliases.sh "$@"
}
vle () {
_edit_locals environ.sh "$@"
}
vlf () {
_edit_locals functons.sh "$@"
}
vwa () {
_edit_work aliases.sh
}
vwe () {
_edit_work environ.sh
}
vwf () {
_edit_work functons.sh
}
vpe () {
edit_source ~/jab/environ.d/python
}
# xxxx
bins () {
local name_="$1"; shift
[[ -z $name_ ]] && return 1
while [[ -n $name_ ]]; do
for root in $HOME /bin /usr; do
find $root -wholename "bin/*$name_*" -print 2>/dev/null
done | grep -e $name_ | sort | uniq | grep $name_ 2>/dev/null
name_="$1"; shift
done
}
bool () {
[[ -z $* || $1 =~ ^0*$ ]] && echo False && return 1
if whyp -q "$1"; then
if [[ $1 == "[[" ]]; then
eval "$@"
local result_=$?
[[ $result_ == 0 ]] && echo True || echo False
return $result_
else
"$@" 2> ~/fd2 && echo True && return 0
fi
echo False; return 1
fi
[[ $1 =~ ^0*$ ]] && echo False || echo True
return 0
}
brew () {
brew_=/usr/local/bin/brew
[[ -f /opt/homebrew/bin/brew ]] && brew_=/opt/homebrew/bin/brew
GIT= $brew_ "$@"
}
bump () {
local show_=
local get_=
local quietly_=
[[ $1 == -q ]] && quietly_=quietly
[[ $1 == -Q ]] && quietly_=QUIETLY
[[ $1 =~ -[qQ] ]] && shift
if [[ $1 == show ]]; then
show_=1
shift
fi
if [[ $1 == get ]]; then
get_=1
shift
fi
local pulled_=
if [[ $1 == pulled ]]; then
pulled_=1
shift
fi
if [[ -d "$1" ]]; then
bumpdir_="$1"
shift
fi
local name_=$(basename_ "$1")
local config_=
[[ $name_ = ".bumpversion.cfg" ]] && config_="$1"
[[ -n $config_ ]] && shift
local bump_root_=$(git_root -q .)
local part_=${1:-patch}; shift
if [[ -z $show_ && -z $get_ ]]; then
if [[ -n $part_ ]]; then
[[ $pulled_ == 1 ]] || git pull --rebase
cd "$bump_root_"
local options_=
[[ -n $config ]] && options_="--config-file $name_"
if bumpversion $options_ $part_ "$@"; then
$quietly_ git push
$quietly_ git push origin v$(bump get)
fi
fi
return $?
fi
[[ -z $config ]] && config_="$bump_root_/.bumpversion.cfg"
[[ -f $config_ ]] || return 2
local sought_=^current_version
if [[ -n $show_ ]]; then
grep $sought_ $config_ | grep --colour '\d[0-9a-z.]\+$'
elif [[ -n $get_ ]]; then
grep $sought_ $config_ | sed -e 's/.*= //'
else
$quietly_ bumpversion "$@"
fi
}
down () {
cde ~/Downloads "$@"
l -tr . | tail
}
hhhh () {
echo '#' | clip_in
}
left () {
local lastcommand_="$1"
echo $last_command
local lastcommand_line_="$@"
echo $last_command_line
}
SUDO () {
if [[ -n $1 ]]; then
user="-u $1"
yousir_="$1"
else
user=
you_sir=root
fi
me=$USER
here=$(jostname)
console_title_on "${you_sir}@${here}" && \
sudo -i $user bash && \
console_title_off "${me}@${here}"
}
dic () {
dixx cp "$1" "$2"
}
dih () {
dixx hd "$@"
}
dii () {
dixx icdiff "$@"
}
div () {
dixx vd "$@"
}
over () {
tput smcup
}
popq () {
popd >/dev/null 2>&1
}
lower () {
echo "$@" | tr '[:upper:]' '[:lower:]'
}
this () {
if [[ "$@" =~ -q ]]; then
pythis
else
local lower_sought=$(lower "$1")
[[ $lower_sought ]] || lower_sought="NOT ACTUALLY LOWER"
echo
pythis | head -n1 | green
echo
while IFS= read -r line; do
local lower_line=$(lower "$line")
if [[ $lower_line =~ $lower_sought ]]; then
lred_line $line
else
lgreen_line $line
fi
done < <(pythis | tail -n+2)
echo
fi
}
Tree () {
tree "$@" | less -R
}
# xxxxx
build () {
if [[ -x bin/make ]]; then
[[ -f bin/made ]] || bin/make "$@"
if [[ -x bin/deploy ]]; then
[[ -e bin/deployed ]] || bin/deploy "$0"
[[ -e bin/deployed ]] && return 0
fi
elif [[ -f build.sh ]]; then bash build.sh "$@"
elif [[ -f Makefile ]]; then make "$@"
fi
}
detab () {
local expand_=$(which expand)
whype -q gexpand && expand_=$(whyp -f gexpand)
if [[ -f "$1" ]]; then
if grep -Pq "^\s*\t\s*[^ \t]" "$1"; then
$expand_ -i --tabs=4 "$1" > /tmp/txt
mv /tmp/txt "$1"
echo detabbed
else
echo no tabs
fi
else
echo not a file "$1"
fi
}
fewer () {
if [[ -n "$@" && -f "$1" ]]; then
local lines_=$(wc -l "$1" | cut -d' ' -f1)
if [[ $lines_ -lt ${LINES:-$(screen_height)} ]]; then
cat -n "$1"
else
lesen "$1"
fi
else
cat -n
fi
}
hello () {
/usr/bin/say -v Moira \
Hello, my name is Moira. \
I am an Irish-English voice. \
}
jalanb () {
local root_=~/src/git/jalanb
for repo in $(readlink -f $root_/*); do
[[ -d $repo ]] || continue
git_dirty $repo || continue
echo
show_command $repo
git -C $repo branch
git -C $repo lg -n 3
git -C $repo status | grep 'Your branch'
git -C $repo status -s
done
}
ncduhd () {
sudo ncdu -x /Volumes/Macintosh\ HD/
}
ncduru () {
sudo ncdu -x /
}
paste () {
if [[ -z "$*" ]]; then
echo "$ $(pbpaste)"
$(pbpaste)
else
echo "# $(pbpaste)"
fi
}
blacken () {
black -S "$@"
QT blackdoc && blackdoc -S --include="[.](md|py|test|tests)" "$@"
}
clipvim () {
bash -x ~/jab/bin/clipvim.sh
}
clip_in () {
pbcopy
[[ "$@" =~ -q ]] || (echo "$(clipout)" | sed -e "s:^:# :")
}
clipout () {
echo "$(pbpaste)"
}
given () {
cat /Users/jab/jab/txt/given.jira.txt | pbcopy
echo "copied"
cp /Users/jab/jab/txt/given.jira.txt ~/tmp/given.txt
vim ~/tmp/given.txt
cat ~/tmp/given.txt | pbcopy
}
gemini () {
npx https://github.com/google-gemini/gemini-cli
}
ptags () {
local source_="$1"
[[ -n $source ]] || source_="."
python ~/jab/src/python/ptags.py $source_
}
pushq () {
pushd "$@" >/dev/null 2>&1
}
quack () {
local result_=1
for item in "$@"; do
if like_duck $item; then
python "$item"
result_=0
fi
done
return $result_
}
range () {
local __doc__="""range(""$@"")"""
local dir_=.
if [[ -n "$*" ]]; then
# local cde_script_=~/hub/cde/cd.py
local cde_script_=~/cde/cde/__main__.py
if ! dir_=$(PYTHONPATH=$python_directory python $cde_script_ "$@" 2>&1); then
echo "$dir_"
return 1
fi
fi
local rlf_=$(readlink -f "$dir_")
if [[ $dir_ != $rlf_ ]]; then
dir_=$rlf_
echo "ranger ($dir_ ->) $rlf_"
elif [[ $dir_ != "$1" && "$1" != "-" ]]; then
echo "ranger $dir_"
fi
pushq "$dir_"
source $(which ranger) $(which ranger)
echo; green_line $PWD; echo; l
return 0
}
taocl () {
curl -s https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README.md |
pandoc -f markdown -t html |
xmlstarlet fo --html --dropdtd |
xmlstarlet sel -t -v "(html/body/ul/li[count(p)>0])[$RANDOM mod last()+1]" |
xmlstarlet unesc | fmt -80
}
ylint () {
python $HOME/jab/src/python/ylint.py "$@"
}
# xxxxxx
bumper () {
if [[ -z $1 ]]; then
echo Please specify branch to bump >&2
return 1
fi
local bump_branch_="$1"; shift
local current_branch_=$(git rev-parse --abbrev-ref HEAD)
if [[ $current_branch_ != $bump_branch_ ]]; then
if git co "$bump_branch_"; then
return
fi
fi
git pull --rebase
bump pulled "$@"
git push
}
cd_one () {
clear
shift_dir "$@" && shift
cde $dir
}
has_py () {
has_ext py "$@"
}
header () {
head -n 1 "$@"
}
howdoi () {
/usr/local/bin/howdoi -c -a "$@"
}
lesser () {
less -R "$@"
}
lese () {
less -SR "$@"
}
lesen () {
less -SNR "$@"
}
mkvenv () {
local dir_=. venv_dir_=
if [[ -d "$1" ]]; then
dir_="$1"
shift
fi
venvdir__="$dir_/.venv"
deactivate
rm -rf $venv_dir_
python3 -m venv "$venv_dir_"
. "$venv_dir_/bin/activate"
piup
}
show_line () {
local prefix_=$1; shift
local server_= suffix_=
[[ $1 ]] && server_=$1
[[ $2 ]] && suffix_=", $2"
echo "$prefix_ ${server_}$suffix_"
}
pysyon () {
local python_path_=/users/jab/pysyte
[[ $PYTHONPATH ]] && pythonpath__="$python_path_:$PYTHONPATH"
PYTHONPATH="$python_path_" python "$@"
}
pythis () {
$(python_command) -c "import this"
}
please () {
local command_=$(history -p !-1)
[[ "$@" ]] && command_="$@"
command_=$(eval echo "$command_")
show_run_command sudo $command_
}
qwerty () {
echo '` 1 2 3 4 5 6 7 8 9 0 - = '
echo 'q w e r t y u i o p [ ]'
echo 'a s d f g h j k l ;' "'" '#'
echo '\ z x c v b n m , . /'
}
run_as () {
username=$1
shift
if [[ -n "$1" ]]; then
sudo -u $username "$@"
else
SUDO $username
fi
}
tailer () {
tail -n 1 "$@"
}
# xxxxxxx
aliases () {
local sub_dir_="src/bash"
[[ $1 == -l ]] && sub_dir_="local"
[[ $1 == -w ]] && sub_dir_="work"
echo "$HOME/jab/${sub_dir_}/aliases.sh"
}
brewup () {
local update_=
if [[ $@ ]]; then
update_=1
else
brew upgrade "$@" > ~/tmp/brew.upgrade.out 2> ~/tmp/brew.upgrade
grep "You have [0-9]+ outdated formulae" ~/tmp/brew.upgrade.out && update_=1
grep "[0-9]+ outdated cask installed" ~/tmp/brew.upgrade.out && update_=1
fi
if [[ $update_ ]]; then
brew update
fi
[[ $* ]] || return 0
brew upgrade "$@"
}
clearly () {
clear
l
}
doctest () {
local __doc__="""doctest args"""
local pythonpath_=$(readlink -f .)
[[ $PYTHONPATH ]] && pythonpath_="$PYTHONPATH:$pythonpath_"
local options_=
if [[ $1 =~ [-][vf] ]]; then
options_="$1"
shift
fi
local target_="$@"
[[ $target_ ]] || target_=.
(PYTHONPATH="$pythonpath_" python -m doctest $options_ -o REPORT_ONLY_FIRST_FAILURE -o FAIL_FAST "$target_")
}
has_ext () {
[[ -n $(ls ${2:-.}/*."$1" 2>/dev/null | grep -v -e fred -e log | head -n 1) ]]
}
cde_bash () {
show_command "$@"
local cde_="$CDE_DIR" cde_out_="$cde_/std.out" cde_err_=$cde_/std.err
local result_=0
"$@" > $cde_out_ 2> $cde_err_ && result_=$?
show_pass $(cat $cde_out_)
show_fail $(cat $cde_err_)
return $result_
}
headline () {
[[ "$1" ]] && head -n 1 "$1" || cat | head -n 1
}
tailline () {
[[ "$1" ]] && tail -n 1 "$1" || cat | tail -n 1
}
is_a_dir () {
[[ -d "$1" ]] || echo "\"$1\" is not a directory" >&2
[[ -d "$1" ]]
}
playbook () {
ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook "$@"
}
relpath () {
python ~/jab/src/python/relpath.py "$@"
}
whiches () {
local which_=$(which "$1")
local located_=
for located_ in $(locate -f "$1"); do
echo
if $located_ --version >/dev/null 2>&1; then
$located_ --version | grep --color ' [0,7,8]\.[0-9]'
ll $located_ | grep --color $which_ || ll $located_
fi
done
}
umports () {
local old_venv_=$VIRTUAL_ENV
local pysyte_=$HOME/jalanb/pysyse/__main__
QUIETLY deactivate
source $pysyte_/.venv/bin/activate
for file in "$@"; do
reorder-python-imports "$file"
python -m pysyte.imports -ume "$file"
done
QUIETLY deactivate
[[ $old_venv_ ]] || return 0
source $old_venv_/bin/activate
}
# xxxxxxxx
doctests () {
.venv/bin/pytest --doctest-modules --doctest-glob=*.test --doctest-glob=*.tests --doctest-glob=*.md
}
functons () {
local sub_dir_="src/bash"
[[ $1 == -g ]] && sub_dir_="$sub_dir_/git"
[[ $1 == -l ]] && sub_dir_="local"
[[ $1 == -w ]] && sub_dir_="work"
echo "$HOME/jab/${sub_dir_}/functons.sh"
}
jostname () {
local short_name_=$(hostname -s)
local caps_name_=${HOSTNAME:-hostless}
echo ${short_name_:-$caps_name_}
}
maketest () {
local path_="$1"
if [[ ! -f "$path" ]]; then
echo $path is not a file >&2
return 1
fi
local filename_=$(basename_ $path)
local stem_=${filename%.*}
local classname_=$(python -c "print 'Test%s' % '$stem'.title()")
local methodname_="test_$stem"
local test_file_=$(python -c "import os; print os.path.join(os.path.dirname(os.path.abspath('$path')), 'test', 'test_%s' % os.path.basename('$path'))")
if [[ -f "$test_file" ]]; then
echo $test_file is already a file >&2
return 1
fi
local test_dir_=$(files_dirs $test_file)
[[ -d "$test_dir" ]] || mkdir -p "$test_dir"
sed -e s/TestClass/$classname/ -e s/test_case/$methodname/ ~/jab/src/python/test_.py > $test_file
}
pong_work () {
pong -t3 "$1".$(work "$1")
}
ssh_tippy () {
at_home tippy
vagrant status 2>&1 | grep -q -e 'poweroff' -e 'Run .vagrant up' && vagrant up
vagrant ssh
}
sudo_ssh () {
local host_="$1"; shift
ssh -t -q $host_ "sudo ""$@"
}
thirteen () {
cd_one
3d "$@"
}
todo_edit () {
local todotxt_="~/jab/todo.txt"
local gitoptions_="--git-dir=~/jab/.git --work-tree=~/jab"
if [[ -f todo.txt ]]; then
todo_txt=todo.txt
git_options=
elif [[ -f TODO.md ]]; then
todo_txt=TODO.md
git_options=
fi
v $todo_txt
if git status -s ~/jab/todo.txt 2>&1 | grep -q "M.*$(basename_ ~/jab/todo.txt)"; then
git add ~/jab/todo.txt
git commit -m'more or less stuff to be done' ~/jab/todo.txt
elif svn stat "~/jab/todo.txt" 2>&1 | grep -q "M .* ~/jab/todo.txt"; then
svn ci -m'more or less stuff to be done' "~/jab/todo.txt"
fi
}
files_dirs () {
local __doc__="""echo all args' directories"""
local result_=1
for arg_ in "$@"; do
[[ -e "$arg_" ]] || continue
dirname "$arg_"
result_=0
done
return $result_
}
dirnames () {
local __doc__="""echo all directories in args"""
local result_=1
for arg_ in "$@"; do
[[ -e "$arg_" ]] || continue
[[ -d "$arg_" ]] && echo "$arg_" || dirname "$arg_"
result_=0
done
return $result_
}
quietless () {
"$@" 2> /dev/null
}
twkgit00 () {
is_a_file .git/config || return 1
sed -i -e s/$(work twkgit30)/$(work git)/ .git/config
sed -i -e s/$(work twkgit20)/$(work bots)/ .git/config
sed -i -e s/$(work twkgit31)/$(work bots)/ .git/config
sed -i -e 's!https://$(work git)!https://$(work git)!' .git/config
sed -i -e 's!http://$(work bots)!https://$(work bots)!' .git/config
}
twkgit30 () {
is_a_file .git/config || return 1
local twkgit30_=$(work twkgit30)
sed -i -e s/$(work git)/${twkgit30_}/ .git/config
sed -i -e s/$(work twkgit20)/${twkgit30_}/ .git/config
sed -i -e s/$(work tools)/${twkgit30_}/ .git/config
sed -i -e s/$(work tooltest)/${twkgit30_}/ .git/config
sed -i -e 's,http://${twkgit30_},https://${twkgit30_},' .git/config
}
unittest () {
local __doc__="""unittest args"""
local pythonpath_=$(readlink -f .)
local option_=--failfast
if [[ $1 =~ [-][vf] ]]; then
option_=
shift
fi
[[ $PYTHONPATH ]] && pythonpath_="$PYTHONPATH:$pythonpath_"
local target_="$@"
[[ $target_ ]] || target_=.
(PYTHONPATH="$pythonpath_" python -m unittest $option_ "$target_")
}
# xxxxxxxxx
basenames () {
local result_=1
for arg_ in "$@"; do
[[ -e "$arg_" ]] || continue
basename "$arg_"
result_=0
done
return $result_
}
first_num () {
num=$(python ~/jab/src/python/first_num.py "$@")
args=$(python ~/jab/src/python/first_num.py --Invert "$@")
[[ -n $num ]]
}
is_a_file () {
[[ -f "$1" ]] || echo "\"$1\" is not a file" >&2
[[ -f "$1" ]]
}
viewstyle () {
git status --porcelain "$1" | grep -q . || return 1
git dv "$1"
git add "$1"
git commit
}
autostyle () {
reorder-python-imports "$1"
viewstyle "$1"
autoflake -i --remove-all-unused-imports "$1"
viewstyle "$1"
~/jab/bin/imports --tmp --unused "$1";
viewstyle "$1"
autopep8 -a -a -a -i "$1"
viewstyle "$1"
vim "$1"; git add "$1"; git commit
}
# xxxxxxxxxx
drive_free() {
df -h / | tail -1 | awk '
{
used = int($5)
total = $2; used_size = $3; free_size = $4
printf "Main Drive: %s [", $5
for(i=0; i<used/2; i++) printf "█"
for(i=0; i<50-used/2; i++) printf "░"
printf "] %s free\n", $4
printf "\n"
printf "┌─────────────┬─────────────┬─────────────┐\n"
printf "│ TOTAL │ USED │ FREE │\n"
printf "├─────────────┼─────────────┼─────────────┤\n"
printf "│%11s │%11s │%11s │\n", total, used_size, free_size
printf "└─────────────┴─────────────┴─────────────┘\n"
}'
}
like_duck () {
has_py "$*"
}
al_email () {
echo "$@@al-got-rhythm.net"
}
continuing () {
local answer_=$(ask "Continue ?")
[[ $answer_ =~ [yY] ]]
}
jab_hub () {
local dir_=
local dirs_=
[[ $1 == -d ]] && dirs_=1
[[ $1 == -D ]] && dirs_=2
(
cd ~/hub;
local result_=$(
grep slack -H */.travis.yml | \
sed -e "s/:.*//" -e "s:..travis.yml::" | \
grep -v -e old -e master -e suds | \
sort | uniq
)
[[ $dirs_ == 1 ]] && for dir_ in $result_; do short_dir $dir_; done
[[ $dirs_ == 2 ]] && for dir_ in $result_; do rlf $dir_; done
[[ $dirs_ ]] || echo $result_ | spaces_to_lines
)
}
jab_scripts () {
python ~/jab/src/python/scripts.py "$@"
}
make_it_so () {
please "$@"
}
thirty_two () {
3l "$@"
2
}
diff_two_files () {
! diff -q "$1" "$2" >/dev/null 2>&1
}
any_diff () {
diff_two_files "$1" "$2" && return 0
[[ -z "$3" ]] && return 1
diff_two_files "$1" "$3" && return 0
diff_two_files "$2" "$3" && return 0
return 1
}
# xxxxxxxxxx
# xxxxxxxxxxx
find_recent() {
local days=${1:-1}
find . -type f -mtime -${days} | grep -v \
-e '/\.' \
-e doc.tags \
-e history.sqlite \
-e __pycache__
}
spaces_to_lines () {
tr ' ' '\n'
}
lines_to_spaces () {
tr '\n' ' '
}
# xxxxxxxxxxxx
blank_script () {
[[ -f "$1" ]] && return 1
echo "#! /bin/bash" > "$1"
echo "" >> "$1"
}
github_email () {
al_email github
}
project_root () {
git_root -q "$@" 2>/dev/null && return 0
local arg_= file_= path_=
for arg_ in "$@"; do
for path_ in $(~/jab/bin/parents $arg_); do
for file_ in .bumpversion.cfg .gitignore .travis.tml setup.py requirements.txt README.rst readme.md LICENSE tox.ini; do
if [[ -f $path_/$file_ ]]; then
echo $path_
return 1
fi
done
done
done
return 1
}
# xxxxxxxxxxxxx
disable_spctl () {
sudo spctl --master-disable
}
show_functions () {
local __doc__="""You're mad!!"""
echo all functions? here ye go
declare -f | grep "^[^ ]* ()"
}
one_two_three () {
clear
cd_one "$@"
todo_show
if first_num "$@"; then
3d $num --noreport $args
else
3d 1 --noreport "$@"
fi
l $(ls1 -p | grep -v "\(pyc\|/\)$")
}
insert_commas () {
# From http://shallowsky.com/blog/linux/cmdline/sed-improve-comma-insertion.html
sed ':a;s/\b\([0-9]\+\)\([0-9]\{3\}\)\b/\1,\2/;ta'
}
sudo_default () {
sudo_ssh default "$@"
}
three_two_one () {
clear
3d 2 "$@"
todo_show