-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bash_aliases
1411 lines (1226 loc) · 62 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
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
#!/bin/bash
# .bash_aliases for GNU Bash v4+
# (c) 2011-2021 Lilian BESSON
# GPLv3 Licensed
# Cr@ns: https://perso.crans.org/besson
# On Bitbucket: https://bitbucket.org/lbesson/bin/
# A try with erase line.
function LS_ECHO() {
printf " ${blue}${u} Listing${reset} \$*..."
sleep 0.5
printf "${el}..."
for i in "$@"; do
printf "${green}$i${reset}..."
sleep 0.05
printf "${el}..."
done
printf "${red}Done !${reset}"
}
# Commandes mv :
alias mv='/bin/mv -i'
# Commandes ls avec diverses options :
# The 'ls' family (this assumes you use the GNU ls)
alias sl='ls'
function la() {
arg=$(history | tail -n1 | sed s/'^.*la '/''/)
if [[ X"$@" = X ]]; then
echo -e "Contenu du dossier $reset${u}$(pwd)$U$white ${magenta}[option -A]$white"
else
echo -e "Liste des fichiers pour $reset$u$arg$U$white ${magenta}[option -A]$white"
fi
/bin/ls --color=auto -A "$@"
}
function l() {
arg="$(history | tail -n1 | sed s/'^.*l '/''/)"
if [[ X"$@" = X ]]; then
echo -e "Contenu du dossier $reset${u}$(pwd)$U$white ${magenta}[option -hCF]$white"
else
echo -e "Liste des fichiers pour $reset$u$arg$U$white ${magenta}[option -hCF]$white"
fi
/bin/ls --color=auto -hCF "$@"
}
function lnc() {
arg="$(history | tail -n1 | sed s/'^.*l '/''/)"
if [[ X"$@" = X ]]; then
echo -e "Contenu du dossier $(pwd) [option -hCF]"
else
echo -e "Liste des fichiers pour $arg [option -hCF]"
fi
/bin/ls --color=never -hCF "$@"
}
alias lD='find . -maxdepth 1 -type d | sort' # To print directory
alias ll='/bin/ls --color=auto -larth' # all in the current dir
alias lsnocolor='/bin/ls --color=no' # the lnc function is better
alias lt='/bin/ls --color=auto -lSrha' # print all, sorted by size
alias lx='/bin/ls --color=auto -lXB' # sort by extension
alias lk='/bin/ls --color=auto -lSr' # sort by size
alias lc='/bin/ls --color=auto -lcr' # sort by change time
alias lu='/bin/ls --color=auto -lur' # sort by access time
alias lr='/bin/ls --color=auto -lR' # recursive ls
alias lm='/bin/ls --color=auto -al | less' # pipe through 'more'
alias tree='tree -Csuh' # nice alternative to 'ls'
# Shortcuts on cp
alias cp='/bin/cp -iv'
alias h='history'
alias which='type -all'
alias ..='cd ..'
alias .1='cd ..'
alias ...='cd ../..'
alias ....='cd ../..'
alias .2='cd ../..'
alias .....='cd ../../..'
alias .3='cd ../../..'
alias ......='cd ../../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
alias .6='cd ../../../../../..'
alias path='echo -e ${PATH//:/\\n}'
function up() { DEEP=$1; cd "$(python -c "print('../'*${DEEP})")"; }
# Commande dut : 'du' Trie. dush : total du dossier courant.
alias dut='/usr/bin/du -kx | egrep -v "\./.+/" | sort -n'
alias dush='/usr/bin/du -sh'
alias du='/usr/bin/du -khc'
alias df='/bin/df -h -l -t ext3 -t ext4 -t fuseblk -t vfat'
alias free='/usr/bin/free -h'
# Commandes avec GNU-Nano :
alias nano='xtitle "($(date)<$USER@$HOSTNAME>:[$(pwd)]> { GNU Nano 6.2 (/bin/nano) }" ; /bin/nano --tabsize=8 --softwrap --const --boldtext --multibuffer --preserve --backup --historylog --nonewlines --quickblank --wordbounds'
alias MAKE="/usr/bin/make -w"
# alias make='mymake.sh'
# XXX Experimental function that adds shortcuts :
# If 'make foo' worked, then 'alias foo="make foo"' is added to the CURRENT bash session
# I got the idea on Saturday 27-08-16 at Lausanne, and I find it pretty awesome
function make() {
mymake.sh "$@"
returncode="$?"
if [ X"${returncode}" = X"0" -a X"${#@}" = X"1" -a X"${1:0:1}" != X"-" ]; then
# XXX We only add an alias for make commands with one argument, to avoid capturing the options
if alias -p | grep -o "^alias $1='mymake.sh $1'$" &>/dev/null; then
echo -e "The previous make command ('${black}make ${1}${white}') ${green}worked${white}, but ${blue}${1}${white} has already been aliased : ${green}nothing to do :-)${white}\n(mymake.sh does not override existing aliases...)"
else
echo -e "The previous make command ('${black}make ${1}${white}') ${green}worked${white}, and ${blue}${1}${white} has not been aliased yet..."
alias $1="mymake.sh $1"
echo -e " '${blue}${1}${white}' is now registered as a ${yellow}new alias${white} for '${black}make ${1}${white}' ..."
fi
fi
# Cf. https://stackoverflow.com/questions/10448160/ddg#10457902
if [ X"${returncode}" = X"0" ]; then
echo # empty line, does nothing
else
( exit "${returncode}" ) # propagate the 'make' error code
fi
}
# Ajout de securite sur la commande 'rm' :
alias delete='echo -e "Supression avec une seule confirmation ?"; /bin/rm -I'
alias rm='/bin/rm -vi'
alias _cd_old='cd' # Does not work
function CD() {
p="$(pwd)"
p2="$(pwd -P)"
if [ "X$@" = "X" ]
then
args="$HOME"
else
args="$*"
fi
if [ "X$p" = "X$p2" ]
then
echo -e "Vous ${yellow}quittez${white} le dossier ${blue}'$p'${white}.\n\tDirection ==> ${green}$args${white}"
_cd_old "$args"
else
echo -e "Vous ${red}quittez${white} le dossier ${yellow}'$p'${white}.\n\t/!\\ Chemin ${red}relatif${white}, car le vrai est ${blue}'$p2'${white}.\n\tDirection ==> ${green}$args${white}"
_cd_old "$args"
fi
}
# Magie noire
alias cd..="CD .."
alias cdBack='CD "${OLDPWD:=$PWD}"' # Nul : cd - fait la même chose !
alias -- -='cd -' # Cf. http://askubuntu.com/a/146034/
alias cdP='cd "$(pwd -P)"'
alias cd="CD"
# ----------------------------------------------------------------------
# Options for a better cd command, cf. https://github.com/mrzool/bash-sensible#sensible-bash
# Prepend cd to directory names automatically
shopt -s autocd 2> /dev/null
# Correct spelling errors during tab-completion
shopt -s dirspell 2> /dev/null
# Correct spelling errors in arguments supplied to cd
shopt -s cdspell 2> /dev/null
# This defines where cd looks for targets
# Add the directories you want to have fast access to, separated by colon
# Ex: CDPATH=".:~:~/projects" will look for targets in the current working directory, in home and in the ~/projects folder
# CDPATH=".:~/publis/:~/ownCloud/cloud.openmailbox.org/"
# Commandes avec SSH :
#alias ssh='/usr/bin/ssh -X -C' # don't send X server, see http://www.hackinglinuxexposed.com/articles/20040705.html
alias ssh='/usr/bin/ssh -C'
# Des commandes auxquelles on rajoute des messages inutiles :
function mkdir() {
echo -e "Le système va essayer de créer le dossier $*..."
/bin/mkdir -p "$@"
}
# Une commande geek pour afficher une video en ASCII ... en console !
alias VideoAscii='mplayer -vo caca'
# Pour convertir des fichiers textes :
alias dos2unix='recode dos/CR-LF..l1'
alias unix2win='recode l1..windows-1250'
alias unix2dos='recode l1..dos/CR-LF'
# Pour installer directement :
alias Installer='echo -e "Recherche des paquets demandés... Veuillez rentrer votre mot de passe :"; sudo apt install'
# Pour prononcer un son :
alias Prononcer='espeak -s 170 -v french --stdin'
# Avec nautilus
alias nautici='echo -e "Ouverture de Nautilus dans le repertoire courant [${blue}$(pwd)${white}]... en cours de traitement..." && nautilus "$(pwd)" &> /dev/null &'
# Support de l'outil LEDIT pour un meilleur toplevel ocaml.
alias leditocaml='ledit -x -h ocaml_history.ml ocaml'
alias leocaml='rlwrap -t dumb --file=/home/lilian/bin/keyword_mocaml_rlwrap.txt --renice --remember -Acm -aPassword: -pGreen --break-chars "() {}[],+-=&^%$#@\"" --histsize 3000000 -H ocaml_history.ml ledit -x -u -l $COLUMNS -h ocaml_history.ml ocaml'
alias rlocaml='rlwrap -t dumb -z count_in_prompt --file=/home/lilian/bin/keyword_mocaml_rlwrap.txt --renice --remember -Acm -aPassword: -pGreen --break-chars "() {}[],+-=&^%$#@\"" --histsize 3000000 ocaml'
alias mocaml='rlwrap -t dumb --file=/home/lilian/bin/keyword_mocaml_rlwrap.txt --renice --remember -Acm -aPassword: -pGreen --break-chars "() {}[],+-=&^%$#@\"" --histsize 3000000 -H mocaml_history.ml ledit -x -u -l $COLUMNS -h mocaml_history.ml ocaml'
alias mocaml_noANSI='rlwrap -t dumb --file=/home/lilian/bin/keyword_mocaml_rlwrap.txt --renice --remember -Acm -aPassword: -pGreen --break-chars "() {}[],+-=&^%$#@\"" --histsize 3000000 -H mocaml_history.ml ledit -x -u -l $COLUMNS -h mocaml_history.ml /home/lilian/.mocaml/launch_noANSI.sh'
# Interpréter les fichiers. Bien mieux que 'ocaml file1.ml file2.ml'.
function ocamls() {
for i in "$@"; do
cat "${i}" >> /tmp/iocaml.ml
echo -e "(** OCaml on ${i}:1:1 *)" >> /tmp/iocaml.log
/usr/bin/ocaml graphics.cma < "${i}" 2>&1 | tee -a /tmp/iocaml.log | sed s_//toplevel//_"${i}"_ | pygmentize -l ocaml -P encoding="$(file -b --mime-encoding "${i}")"
done
}
# TODO this requires https://github.com/andrewray/iocaml/#installation (and maybe some local hack to make it work)
# alias jupyter-iocaml='DYLD_LIBRARY_PATH=/home/lilian/.opam/4.04.2/lib/stublibs/ && eval $(opam config env) && jupyter notebook --Session.key="b\"\""'
# Export this parameter, see https://ocaml.org/docs/debugging#printing-a-back-trace-for-an-uncaught-exception
export OCAMLRUNPARAM=b
# Convert Jupyter notebooks
alias j='jupyter-notebook' # might be changed
alias ju='jupyter-notebook'
alias j2html='jupyter-nbconvert --to html'
alias j2pdf='jupyter-nbconvert --to pdf'
function _j2pdf() {
for old in "$@"; do
jupyter-nbconvert --to pdf "$old"
# new="${old%.ipynb}__fix-iocaml-notebook-exports-to-pdf.ipynb"
# [ -f "$new" ] && mv -vf "$new" /tmp/
# fix-iocaml-notebook-exports-to-pdf.py "$old" "$new"
# if [ $? = 0 ]; then
# jupyter-nbconvert --to pdf "$new"
# [ -f "${old%.ipynb}.pdf" ] && mv -vf "${old%.ipynb}.pdf" /tmp/
# mv -vf "${new%.ipynb}.pdf" "${old%.ipynb}.pdf"
# mv -vf "$new" /tmp/
# else
# jupyter-nbconvert --to pdf "$old"
# fi
done
}
alias j2webpdf='jupyter-nbconvert --to webpdf'
alias j2slides='jupyter-nbconvert --to slides'
alias j2script='jupyter-nbconvert --to script'
alias j2py='jupyter-nbconvert --to python'
alias j2ml='jupyter-nbconvert --to ocaml' # With https://github.com/Naereen/Jupyter-NBConvert-OCaml/
alias j2ju='jupyter-nbconvert --to julia'
function j2java() {
for old in "$@"; do jupyter-nbconvert --to script "$old"; mv "${old%.ipynb}.jshell" "${old%.ipynb}.java" ; done
}
function j2rust() {
for old in "$@"; do jupyter-nbconvert --to script "$old"; done
}
function j2c() {
for old in "$@"; do jupyter-nbconvert --to script "$old"; done
}
function j2pyhtml() {
for old in "$@"; do jupyter-nbconvert --to html "$old"; jupyter-nbconvert --to python "$old"; done
}
function j2all() {
for old in "$@"; do
echo -e "\nConverting '${old}' to HTML, Slides HTML, PDF, and source code"
jupyter-nbconvert --to html "$old"
jupyter-nbconvert --to slides "$old"
kernelname=$(grep -A 3 '"kernelspec"' "$old" 2>/dev/null| grep -o '"name": ".*"' 2>/dev/null | sed 's/"name": //g' | tr -d '"')
# DONE?: detect extension and run --to appropriate command
# # grep -A 3 kernel *nb | grep -o '"name": ".*"' | sed 's/"name": //g' | tr -d '"'
# # On 6 different kernels: bash, c, java, ocaml-jupyter, python3, rust
case "${kernelname:-script}" in
ocaml* )
j2ml "$old" ;;
rust* )
j2rust "$old" ;;
java* )
j2java "$old" ;;
python* )
j2py "$old" ;;
c )
j2c "$old" ;;
* )
jupyter-nbconvert --to script "$old" ;;
esac
# PDF last, as it can break
jupyter-nbconvert --to pdf "$old"
done
}
complete -f -X '!*.ipynb' -o plusdirs j j2html j2pdf j2webpdf j2slides j2script j2py j2ml j2ju j2c j2java j2rust j2pyhtml j2all
function show_imported_from_python_module() {
python3 -c "from $1 import *; g=dict(globals()); print([s for s in g if s[0]!='_'])"
}
alias iocaml='jupyter-console --kernel=ocaml-jupyter'
# Reference for this is https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
complete -f -X '!*.ml' -o plusdirs ocaml ocamlc ocamlopt leocaml leditocaml rlocaml mocaml mocaml_noANSI ocamls iocaml iocaml.sh jupyter-iocaml
########################################################################
# Outil pygmentize : permet une coloration syntaxique dans la console
case $TERM in
*dumb*|*term*)
CAT_COLOR="terminal256"
export CAT_COLOR="terminal256"
;;
*)
CAT_COLOR="terminal"
export CAT_COLOR="terminal"
;;
esac
alias catColor='pygmentize -f $CAT_COLOR -g'
function ExportColorLaTeX() {
pygmentize -f latex -P encoding=utf8 -o "$1.tex" "$1"
}
function ExportColorLaTeXFull() {
pygmentize -f latex -P encoding=utf8 -O full -o "$1.full.tex" "$1"
}
########################################################################
export RLWRAP_HOME='/home/lilian/'
export RLWRAP_EDITOR='/home/lilian/bin/nano.last --autoindent --tabsize=8 --softwrap --suspend --const --smooth --rebindkeypad --boldtext --multibuffer --preserve'
function voirImage() {
for image in "$@"; do
echo -e "L'image '${image}' va etre affichee en ASCII."
if [ -f "${image}" ]; then
convert "${image}" jpg:- | jp2a -b -f --colors -
fi;
done
}
# Ajout d'une bash complétion comme ça, en une ligne !
complete -f -X '!*.@(gif|GIF|jpg|jpeg|pn[gm]|PN[GM]|ico|ICO)' -o plusdirs voirImage
complete -f -X '!*.@(png|PNG)' -o plusdirs advpng
complete -f -X '!*.@(jpg|jpeg|JPG|JPEG)' -o plusdirs cjpeg djpeg jpegexiforient jpegoptim jpegtopnm jpegtran
complete -f -X '!*.@(gif|GIF)' -o plusdirs gifcompress gifcurry gifdiff gifsicle giftopnm gifview gif2mp4.sh
function xtitle() {
echo -e "${reset}Setting title to $@..." >> /tmp/xtitle.log
echo -e "${cyan}Setting title to ${white}${u}$*${U}...${reset}${white}"
if [ -x /usr/bin/xtitle ]; then
/usr/bin/xtitle "$@"
fi
}
# Autre outils pratiques
function Regler_son() {
xtitle "$(date)<$USER@$HOSTNAME> { AlsaMixer v1.0.25 }" || true
clear ; alsamixer; clear
}
function Wavemon() {
xtitle "$(date)<$USER@$HOSTNAME> { Wavemon v0.7.6 }" || true
clear ; wavemon; clear
}
function t() {
xtitle "$(date)<$USER@$HOSTNAME> { htop 1.0.3 }" || true
htop || alert
clear
}
function captureEcran() { # now the Alt+$ shortcut does the same!
sleep 3s
xfce4-screenshooter -r -d 5 || gnome-screenshot -i
clear
}
alias manH='man -Helinks'
alias Byobu='echo -e "You should rather use TMUX instead"; byobu -A -D -RR -fa -h 150000 -l -O -U' # TMUX is better
alias Byobu-tmux='byobu-tmux -2 -q -u'
# http://unix.stackexchange.com/a/1098
alias byobu='TERM=xterm-256color /usr/bin/byobu-tmux -2 -q -u'
alias py2html='pyhtmlizer --stylesheet=https://perso.crans.org/besson/pyhtmlizer.css'
complete -f -X '!*.@(py|py3)' -o plusdirs py2html pylint flake8 pep8
# Ecrans de veilles
alias MatrixVeille='cmatrix -b -f -s -u 9'
# Screensaver (very CPU expensive) in texts mods, using libcaca examples (cacademo or cacafire)
alias cacademoTerminal='OLDDISPLAY=$DISPLAY; DISPLAY=""; cacademo; DISPLAY=$OLDDISPLAY'
alias cacafireTerminal='OLDDISPLAY=$DISPLAY; DISPLAY=""; cacafire; DISPLAY=$OLDDISPLAY'
function lessColor() {
for i in "$@"; do
pygmentize -P encoding="$(file -b --mime-encoding "${i}")" -f $CAT_COLOR -g "${i}" | less -r || \
echo -e "${ERROR} LessColor failed to read ${u}${i}${U} ...${white}" > /dev/stderr
done
}
## Emuler l'appuis sur les touches de volumes (ne fonctionne temporairement plus)
alias SoundMute='echo -e KeyStrPress XF86AudioMute KeyStrRelease XF86AudioMute | xmacroplay $DISPLAY > /dev/null >& /dev/null'
alias SoundUp='echo -e KeyStrPress XF86AudioRaiseVolume KeyStrRelease XF86AudioRaiseVolume | xmacroplay $DISPLAY > /dev/null >& /dev/null'
alias SoundDown='echo -e KeyStrPress XF86AudioLowerVolume KeyStrRelease XF86AudioLowerVolume | xmacroplay $DISPLAY > /dev/null >& /dev/null'
alias RaiseSound='echo -e KeyStrPress XF86AudioRaiseVolume KeyStrRelease XF86AudioRaiseVolume | xmacroplay $DISPLAY > /dev/null >& /dev/null'
alias LowerSound='echo -e KeyStrPress XF86AudioLowerVolume KeyStrRelease XF86AudioLowerVolume | xmacroplay $DISPLAY > /dev/null >& /dev/null'
# Variable utiles pour faire des scp et des rsync facilement
export SDPT='lbesson@ssh.dptinfo.ens-cachan.fr'
export SZAM='besson@zamok.crans.org'
export Sdpt='lbesson@ssh.dptinfo.ens-cachan.fr:~/public_html/'
export Szam='besson@zamok.crans.org:~/www/'
export toprint="${Szam}dl/.p/toprint/"
export Sjarvis=~/"Public/"
export SWS3='lilian_besson@ws3'
export Sw='lilian_besson@ws3:~/'
export SFORGE='lbesson@scm.gforge.inria.fr'
export Sforge='lbesson@scm.gforge.inria.fr:/home/groups/banditslilian/htdocs/'
# For http://besson.link/ and https://besson.link/
export FOVH='ftp://bessonlihy@ftp.cluster028.hosting.ovh.net:21'
export SOVH='bessonlihy@ftp.cluster028.hosting.ovh.net'
export Fovh='ftp://bessonlihy@ftp.cluster028.hosting.ovh.net:~/www/'
export Sovh='bessonlihy@ftp.cluster028.hosting.ovh.net:~/www/'
# FIXME SSH don't work, use a durty hack! CP and rsync don't work, but cp does!
export Sovh='Sovh=/run/user/1001/gvfs/ftp:host=ftp.cluster028.hosting.ovh.net/www/'
# Play an ASCII version of Star Wars, A new hope
alias telnet_starwars='telnet towel.blinkenlights.nl'
# Un outil pour les messages du jour
alias motd='changemotd.sh --print'
function chmotd() {
if [ "X$DISPLAY" = "X" ]; then
echo -e "Using : dialog."
changemotd.sh --new-dialog
else
echo -e "Using : zenity."
changemotd.sh --new-zenity
fi
}
function SMSmotd() {
FreeSMS.py "$(tail -n +2 ~/motd)"
}
function LessColor() { pygmentize -f $CAT_COLOR -g "$@" | less -r; }
# Un meilleur 'scp'. Ne fonctionne pas avec tous les serveurs, car la cible doit avoir rsync aussi.
# NOTE: fonctionne aussi en local (et donne un avancement et propose une compression, meme en local).
alias rsync='/usr/bin/rsync --verbose --times --perms --compress --human-readable --progress --archive'
# Deprecated: use http://besson.qc.to/bin/CP instead (with colours!)
function DOCXtoPDF() { for i in "$@"; do echo -e "${i} ----[abiword]----> ${i%.docx}.pdf"; abiword "${i}" --to="${i%.docx}.pdf"; echo -e "$?"; done }
# Netoyer les fichiers temporaires (sauvegarde, python, ou emacs)
alias rmPyc='rm -vrI ./*.py[co] ./__pycache__/ && echo "Local Python compiled files (*.pyc and *.pyo) have been deleted..."'
alias rmt='rm -vrI ./*~ ./.*~ ./*.py[co] ./__pycache__/ ./\#*\#'
function rmTilde() {
if [ X"$1" != X"" ]; then
for i in "$@"; do
# d="$(basename \"$i\")" # ? inutile ?
d="$i"
echo -e "rm -vrI" "$d"/*~ "$d"/.*~ "$d"/*.py[co] "$d"/__pycache__/ "$d"/\#*\#
rm -vrI "$d"/*~ "$d"/.*~ "$d"/*.py[co] "$d"/__pycache__/ "$d"/\#*\#
done
echo -e "Fichiers temporaires (*~ .*~) bien supprimes."
else
echo -e "rm -vrI" ./*~ ./.*~ ./*.py[co] ./__pycache__/ ./\#*\#
rm -vrI ./*~ ./.*~ ./*.py[co] ./__pycache__/ ./\#*\# && \
echo "Fichiers temporaires (*~ .*~) bien supprimes."
fi
}
alias rmt=rmTilde
alias rm~="rmTilde *"
# Netoyer les fichiers temporaires crees par LaTeX (pdflatex et hevea)
function rmLaTeX() {
echo -e "# ${blue}rmLaTeX:${white}"
for i in ./*.tex; do
echo -e "# For the file ${yellow}${u}$i${U}${white}:"
for j in "${i%tex}dvi" "${i%tex}htoc" "${i%tex}frompdf[0-9]*.png" "${i%tex}bbl" "${i%tex}blg" "${i%tex}brf" "${i%tex}tms" "${i%tex}tid" "${i%tex}lg" "${i%tex}idv" "${i%tex}vrb" "${i%tex}toc" "${i%tex}snm" "${i%tex}nav" "${i%tex}htmp" "${i%tex}synctex.gz" "${i%tex}synctex.gz(busy)" "${i%tex}aux" "${i%tex}fdb_latexmk" "${i%tex}fls" "${i%tex}log" "${i%tex}tmp" "${i%tex}idx" "${i%tex}aux" "${i%tex}out" "${i%tex}haux" "${i%tex}hidx" "${i%tex}thm" "${i%tex}listing" "${i%tex}tns" "${i%tex}records"; do
mv -vf "$j" /tmp/ 2>/dev/null
done
echo -e "Fichiers $(ls --color=always --format=horizontal ${i%tex}html ${i%tex}pdf) : conserves..."
done
}
# A super pdflatex
function tex2pdf() {
for i in "$@"; do
i="${i//.pdf/.tex}"
( pdflatex "$i" && pdflatex "$i" && mv -f "${i%tex}log" "${i%tex}aux" "${i%tex}synctex.gz" "${i%tex}out" "${i%tex}vrb" "${i%tex}listing" "${i%tex}records" "${i%tex}snm" "${i%tex}nav" "${i%tex}toc" /tmp/ 2>/dev/null ) || (chktex "$i" ; alert )
done
}
function TEX2PDF() {
for i in "$@"; do
i="${i//.pdf/.tex}"
( pdflatex "$i" && pdflatex "$i" && mv -f "${i%tex}log" "${i%tex}aux" "${i%tex}synctex.gz" "${i%tex}out" "${i%tex}vrb" "${i%tex}listing" "${i%tex}records" "${i%tex}snm" "${i%tex}nav" "${i%tex}toc" /tmp/ 2>/dev/null ) || (clear ; chktex "$i" ; alert )
PDFCompress "${i%tex}pdf"
done
}
complete -f -X '!*.@(tex|pdf)' -o plusdirs tex2pdf TEX2PDF qpdf
# A small alias to extract .mkv to .aac or .ogg or .mp3 using ffmpeg
function mkv2sound() {
ext="$1"
shift
for input in "$@"; do
base="${input//.mkv}"
output="${base}.${ext}"
# Cf. https://askubuntu.com/a/1204043
echo ffmpeg -i "$input" "$output"
ffmpeg -i "$input" "$output"
done
}
alias mkv2aac='mkv2sound aac'
alias mkv2ogg='mkv2sound ogg'
alias mkv2mp3='mkv2sound mp3'
complete -f -X '!*.@(mkv)' -o plusdirs mkv2sound mkv2aac mkv2ogg mkv2mp3
# A small alias to convert .md to .pdf with Pandoc
function md2pdf() {
for i in "$@"; do
i="${i//.pdf/.md}"
pandoc --verbose --to=latex --output="${i%md}pdf" "$i"
# [ -f "{i%md}pdf" ] && PDFCompress "${i%md}pdf"
# [ -f "{i%md}pdf" ] && evince "${i%md}pdf" &>/dev/null&
done
}
complete -f -X '!*.@(md|pdf)' -o plusdirs md2pdf
function marp2html() {
for i in "$@"; do
marp --config ~/publis/slides/common/.marprc-html.yml "$i"
done
}
function marp2pdf() {
for i in "$@"; do
marp --config ~/publis/slides/common/.marprc-pdf.yml "$i"
done
}
function marp2all() {
for i in "$@"; do
marp --config ~/publis/slides/common/.marprc-html.yml "$i"
marp --config ~/publis/slides/common/.marprc-pdf.yml "$i"
done
}
complete -f -X '!*.md' -o plusdirs marp2pdf marp2html marp2all
# A better and smaller bibtex2html command, with good options
alias bib2html='bibtex2html -u -charset utf-8 -linebreak -debug'
complete -f -X '!*.@(bib)' -o plusdirs bibtex2html bib2html
# N'afficher que les processus lances par l'utilisateur courant dans htop.
alias Htop='htop -u $USER'
# Pour afficher la temperature.
alias TempDisk='echo -e "Hard drive temperature : ${green}$(($(sudo hddtemp --numeric --wake-up /dev/disk/by-label/SYSTEM)))${white} °C."'
# Affiche la taille du repertoire courant. Peut etre long a calculer !
alias TailleCourante='LS_ECHO -e "*"; echo -e "${el}Taille du repertoire ${u}courant${U} : \033[01;31m`du -sh \"\`pwd -P\`\"`\033[01;37m"'
# Simply shutdown the main screen (force it to be black!)
alias VeilleEcranNoir='xset dpms force standby'
alias VeilleEcranNoirContinue='watch --interval=1 "echo -e \"Screen is sleeping, Ctrl+C, ^C to cancel.\" ; xset dpms force standby"'
alias IpAdresses='ifconfig | grep "inet"'
alias SpeedTest="wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test100.zip"
# Get Linux kernel versions and informations
alias version='cat /proc/version ; lsb_release -a'
# Check today content of Google Calendar
alias CheckGoogleCalendar='gcalcli agenda today tomorrow'
alias CalendarRandQuote='gcalcli --calendar "amelia"."noreen"@"gmail"."com" quick "$(randquote)"'
# Gobby Server
alias SOBBY='sobby -p 6522 --password 120193 --autosave-file=/home/lilian/.gobby.savefile --autosave-interval=10'
# Via monip.org
alias AdressIP='echo -e "# From http://monip.org/ :" ; wget --tries=5 -q -O - http://monip.org/ | html2text ; echo -e "\n# From http://ipinfo.io/ :" ; (type ipinfo.sh &>/dev/null && ipinfo.sh || curl http://ipinfo.io/) '
# Efface les fichiers temporaires dus à un Mac qui a monté le disque
alias EffacePresenceAPPLE='find -type d -name *Apple* -exec rm -vrI {} \;'
# Affiche tous les programmes dans le $PATH.
alias LS_PATH='ls ${PATH//:/ }'
function LOG_Colored() {
"$@" 2> /tmp/LOG_Colored.log
printf "${reset}${el}\a"
catColor /tmp/LOG_Colored.log
}
# Shortend to git
alias GitChanged='clear ; git status | grep --color=always "\(modified\|modifié\)" | less -r'
alias GitDeleted='clear ; git status | grep --color=always "\(deleted\|supprimé\)" | less -r'
alias GitAdded='clear ; git status | grep --color=always "\(added\|nouveau\)" | less -r'
alias GitSize='clear ; echo -e "\n ==> ${white}Ce dépôt git « ${green}$(basename $(pwd))${white} » pèse ${red}$(git count-objects -v -H | grep "size-pack" | sed s/"size-pack: "//)${white} sur ${u}https://BitBucket.org/lbesson/$(basename $(pwd))${U}${white}."'
# Run all test embedded in docstring, in the module $1
alias DocTest='python -m doctest -v'
alias DocTest3='python3 -m doctest -v'
# Make colorgcc an remplacement for GCC (all makefiles use CC usually)
export CC="colorgcc"
alias diff="colordiff"
alias CowThink='cowthink -W 160 -f /usr/share/cowsay/cows/moose.cow'
# For zip compression (by default, DO NOT FOLLOW symlinks!)
alias zip='/usr/bin/zip -r -9 -y'
# For tar compression
alias TarXZ='tar -Jcvf'
alias TarGZ='tar -zcvf'
alias TarBZ2='tar -jcvf'
# For tar un-compression (see extract for a better commad)
alias untar='echo -e "Desarchivage du fichier archive tar en cours ..." && tar xfv'
alias untar_gz='echo -e "Desarchivage du fichier archive tar.gz en cours ..." && tar xzfv'
alias untar_bz2='echo -e "Desarchivage du fichier archive tar.bz2 en cours..." && tar xjfv'
alias untar_xz='echo -e "Desarchivage du fichier archive tar.xz en cours..." && tar xJfv'
alias unTarXZ='tar -Jxvf'
alias unTarGZ='tar -zxvf'
alias unTarBZ2='tar -jxvf'
alias unTarTBZ='tar -xjvf'
# Use grep to look for TODO or FIXME or FIXED or HOWTO or XXX or DEBUG, or WARNING balises in code
function GrepBalises() {
echo -e "GrepBalises >>> Looking for specials developpement balises in files ${blue}$@${white}."
notfound=""
for balise in 'TODO' 'FIXME' 'FIXED' 'HOWTO' 'XXX' 'DEBUG' 'WARNING'; do
res=$(grep --color=always -n "$balise" $@)
if [ "m$?" != "m1" ]; then
echo -e "${magenta} For the balise $balise :${default}"
echo -e "${res}" # | pygmentize -f terminal256 -g # -l
else
notfound="${notfound}${balise}, "
echo -e "${red} $balise not found in files..." >> /tmp/GrepBalises.log
fi
done
if [ "X$notfound" = "X" ]; then
echo -e "${white}GrepBalises >>> ${green} Done${white}. (on files $*)."
else
echo -e "${white}GrepBalises >>> ${red} Balises ${notfound} not found :("
echo -e "${white}GrepBalises >>> Done. (on files $*)."
fi
}
# Better grep command, using ack-grep, cf. http://beyondgrep.com/
#alias agrep='ack-grep -ri -H --sort-files'
# Even better grep command, using ripgrep, cf. https://github.com/BurntSushi/ripgrep
alias agrep='rg --color=auto'
#alias grep='rg --color=auto' # XXX aggressive!
# Other aliases, from http://abs.traduc.org/abs-5.3-fr/apk.html
# tailoring 'less'
export PAGER=less
export LESSCHARSET='latin1'
export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-'
## Use this if lesspipe.sh exists.
##export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
export LESS=' -r -F -B -i -J -w -W -~ -K -d -w -W -m -X -u -r'
###-P"%t?%f%f :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-..." -e'
#-----------------------------------
# File & strings related functions:
# Find a file with a pattern in name:
function ff() { find . -type f -iname '*'"$@"'*' -ls ; }
# Find a file with pattern $1 in name and Execute $2 on it:
function fe() { find . -type f -iname '*'"$1"'*' -exec "${2:-file}" {} \; ; }
# find pattern in a set of files and highlight them:
function fstr() {
OPTIND=1
local case=""
local usage="fstr: find string in files.
Usage: fstr [-i] \"pattern\" [\"filename pattern\"] "
while getopts :it opt; do
case "$opt" in
i) case="-i " ;;
*) echo "$usage"; return;;
esac
done
shift $(( $OPTIND - 1 ))
if [ "$#" -lt 1 ]; then
echo "$usage"
return;
fi
local SMSO=$(tput smso)
local RMSO=$(tput rmso)
find . -type f -name "${2:-*}" -print0 |
xargs -0 grep -sn "${case}" "$1" 2>&- | \
sed "s/$1/${SMSO}\0${RMSO}/gI" | more
}
function lowercase() { # move filenames to lowercase
for file ; do
filename="${file##*/}"
case "$filename" in
*/*) dirname==${file%/*} ;;
*) dirname=.;;
esac
nf="$(echo $filename | tr '[:upper:]' '[:lower:]')"
newname="${dirname}/${nf}"
if [ "$nf" != "$filename" ]; then
mv "$file" "$newname"
echo "lowercase: $file --> $newname"
else
echo "lowercase: $file not changed."
fi
done
}
function capitalize() { # move filenames to Capitalize
for file ; do
filename="${file##*/}"
case "$filename" in
*/*) dirname==${file%/*} ;;
*) dirname=.;;
esac
premierelettre="${filename:0:1}"
pl="$(echo $premierelettre | tr '[:lower:]' '[:upper:]')"
nf="${pl}${filename:1}"
newname="${dirname}/${nf}"
if [ "$nf" != "$filename" ]; then
mv "$file" "$newname"
echo "capitalize: $file --> $newname"
else
echo "capitalize: $file not changed."
fi
done
}
alias titlecase="python3 -c \"from sys import argv; from titlecase import titlecase; print(titlecase('\n'.join(argv[1:])))\""
function titlecase_all() { # move filenames to Title Case
for file ; do
filename="${file##*/}"
case "$filename" in
*/*) dirname==${file%/*} ;;
*) dirname=.;;
esac
nf="$(titlecase "$filename")"
newname="${dirname}/${nf}"
if [ "$nf" != "$filename" ]; then
mv "$file" "$newname"
echo "titlecase_all: $file --> $newname"
else
echo "titlecase_all: $file not changed."
fi
done
}
function swap() { # swap 2 filenames around
local TMPFILE=tmp.$$
mv "$1" $TMPFILE
mv "$2" "$1"
mv $TMPFILE "$2"
}
function my_ps() { ps "$@" -u "$USER" -o pid,%cpu,%mem,bsdtime,command ; }
function pp() { my_ps f | awk '!/awk/ && $0~var' var="${1:-".*"}" ; }
function my_ip() { # get IP adresses
MY_IP=$(/sbin/ifconfig | awk '/inet adr:/ { print $2 } ' | sed -e s/addr://)
}
function ii() { # get current host related info
echo -e "\nYou are logged on ${blue}$HOSTNAME ($HOSTNAME_WIFI)"
echo -e "\nAdditionnal information:${reset}${white} " ; uname -a
echo -e "\n${blue}Users logged on:${reset}${white} " ; w -h
echo -e "\n${blue}Current date :${reset}${white} " ; date
echo -e "\n${blue}Machine stats :${reset}${white} " ; uptime
echo -e "\n${blue}Memory stats :${reset}${white} " ; free
my_ip 2>&- ;
echo -e "\n${blue}Local IP Address :${reset}${white}" ; echo "${MY_IP:-"Not connected"}"
}
# For Python (2.7)
export PYTHONSTARTUP="$HOME/.pythonrc"
#export PYTHONWARNINGS="ignore"
#export PYTHONOPTIMIZE= # no optimization.
#export PYTHONVERBOSE= # no verbose adds.
# export PYTHONPATH="/usr/local/lib/python2.7/":"/usr/local/lib/python2.7/dist-packages/":"/usr/lib/python2.7/":"/usr/lib/python2.7/dist-packages"
# Avoid a painful bug, as explained here http://stackoverflow.com/a/230780/5889533, see https://docs.python.org/2/using/cmdline.html#envvar-PYTHONUNBUFFERED
export PYTHONUNBUFFERED="yes"
# For PyLint (see http://docs.pylint.org/)
export PYLINTHOME="$HOME/.pylint.d/"
# Supprimer les meta-données des images JPEG et PNG, et PDF
alias CleanPicturesR='echo "Erasing EXIF infos...." && exiftool -v2 -recurse -fast -overwrite_original_in_place -all= ./* | tee "exiftool__$$_$(date "+%H_%M_%S")".log && echo "All EXIF infos have been erased :)"'
alias CleanPictures='echo "Erasing EXIF infos...." && exiftool -v2 -fast -overwrite_original_in_place -all= ./* | tee "exiftool__$$_$(date "+%H_%M_%S")".log && echo "All EXIF infos have been erased :)"'
alias CleanPNG='echo "Cleaning and compressing PNG images..." && exiftool -v2 -fast -overwrite_original_in_place -all= ./*.png && advpng -z -2 ./*.png && M'
alias CleanPDF='echo "Cleaning and compressing PDF images..." && exiftool -v2 -fast -overwrite_original_in_place -all= ./*.pdf && PDFCompress --no-keep ./*.pdf && M'
## A less for PDF files (useless)
function lessPDF() {
for f in "$@"; do
pdftotext -r 200 -layout -eol unix -enc UTF-8 -raw "$f" && less -f -J "${f%.pdf}.txt"
done
}
eval "$(/usr/bin/lesspipe)"
# Man visual
function Man() { yelp "man:$@" ; }
# Le script suivant permet de decompresser un large eventail de types de fichiers compresses. Il vous suffira juste de taper quel que soit le type d'archive :
function extract() {
echo -e "${reset}${neg}Extracting $1...${reset}"
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.tar.xz) tar xvJf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tbz) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*.xz) unxz "$1" ;;
*.exe) cabextract "$1" ;;
*) echo "'$1': unrecognized file compression" ;;
esac
else
echo "'$1' seems to not be a valid archive file, sorry."
fi
}
# Experimental
function LatexFormula() {
out="/tmp/LatexFormula_$$.jpg"
# tente d'afficher les arguments interpretes comme une formule LaTeX, via le bon service web.
wget --quiet 'http://s0.wp.com/latex.php?bg=ffffff&fg=1c1c1c&s=0&zoom=10&latex=\displaystyle'"${@// /+}" -O "${out}" \
|| wget --quiet 'http://numberempire.com/equation.render?'"${@// /%20}" -O "${out}"
display -title "Image for the LaTeX formula: '${@//\\/\\\\}' (thanks to an awesome webservice)" "${out}"
}
alias CheckHomePage_crans='wget -q https://perso.crans.org/besson/index.fr.html -O - | grep "Mis.*jour"'
# alias CheckHomePage_dpt='wget -q http://www.dptinfo.ens-cachan.fr/~lbesson/index.fr.html -O - | grep "Mis.*jour"'
alias CheckHomePage_jarvis='wget -q http://localhost/index.fr.html -O - | grep "Mis.*jour"'
alias GenP="base64 < /dev/urandom | tr -d +/ | head -c 18; echo"
# Pour checker les soucis de droits.
alias MoinsOwner='chmod -vR o-w ./ | tee /tmp/.script_droit_owner.log'
alias MoinsGroup='chmod -vR g-w ./ | tee /tmp/.script_droit_group.log'
alias MOINS='( MoinsOwner ; MoinsGroup) | grep -v symbolique | grep modif'
alias M='MOINS'
alias CheckPerms='find ./ -type d -perm /022'
alias PlusROwner='chmod -vR o+r ./ | tee /tmp/.script_droit_Rowner.log'
alias PlusRGroup='chmod -vR g+r ./ | tee /tmp/.script_droit_Rgroup.log'
alias PLUS='( PlusROwner ; PlusRGroup) | grep -v symbolique | grep modif'
function ViewHTML() {
for i in "$@"; do
echo -e "Trying to see the file at the address ${yellow}'${i}'${white}"
curl --insecure "$i" 2> /tmp/ViewHTML.$$.log | html2text | pygmentize -f terminal -l rst
done
}
alias MacAddress='ifconfig | grep "HWaddr [0-9a-f:]*"'
# --- For Git only ---
alias g='git'
# Thanks to http://stackoverflow.com/a/4529147/5889533
function pushall() {
for i in $(git remote | sort -r); do
echo -e "git push $i ${1}" "..."
git push "$i" "${1}"
done;
}
function pullall() {
for i in $(git remote | sort -r); do
echo -e "git pull $i ${1}" "..."
git pull "$i" "${1}"
done;
}
alias ori='git pull origin main'
# --- For Git and subversion ---
function Push() {
clear
(git push "$@" && git gc) || svn update "$@"
}
function p() {
clear
git push "$@" || svn update "$@"
}
function Pull() {
clear
(pullall "$@" && git gc && [ -x git-blame-last-commit.sh ] && git-blame-last-commit.sh) || svn update "$@"
}
function s() {
clear
( git status "$@" || svn status "$@" ) | less -r
}
alias Status='s'
function wd() {
clear
git wdiff "$@" || svn diff "$@"
}
function c() {
clear
git commit -m "$@" || svn commit -m "$@"
}
alias Commit='c'
function a() {
git add "$@" || svn add "$@"
}
alias Add='a'
function add_modified() { git add $(git status --porcelain | grep '^ M' | awk '{ print $2}'); }
alias Aggressive='git gc --aggressive'
alias Sync='clear ; echo -e "Synchronizing (git push, gc, send_zamok)..."; git push; git gc --aggressive; make send_zamok; alert'
# For gmusicbrowser
alias Get_vrun_Uri="vrun status | grep file | sed s/'( new input: '/''/ | sed s/' )'/''/"
alias Next='gmusicbrowser -cmd NextSong' # && clear ; tmp1=$(vrun get_title); tmp2=$(vrun status|head -n1); echo -e "$u$tmp2$reset${white}\n${green} (→) Playing${white}: $neg$tmp1$Neg"'
alias Prev='gmusicbrowser -cmd PrevSong' # && clear ; tmp1=$(vrun get_title); tmp2=$(vrun status|head -n1); echo -e "$u$tmp2$reset${white}\n${green} (←) Playing${white}: $neg$tmp1$Neg"'
alias Pause='gmusicbrowser -cmd PlayPause' # && clear ; tmp1=$(vrun get_title); tmp2=$(vrun status|head -n1); echo -e "$u$tmp2$reset${white}\n${green} (:) Was Playing${white}: $neg$tmp1$Neg"'
alias Play='gmusicbrowser -cmd Play' # && clear ; tmp1=$(vrun get_title); tmp2=$(vrun status|head -n1); echo -e "$u$tmp2$reset${white}\n${green} (>) Now Playing${white}: $neg$tmp1$Neg"'
# Irssi
alias irc='screen irssi'
# TMUX create a new session ONLY if no other session is already running
alias tmux='TERM=xterm-256color /usr/bin/tmux -2 -q -u'
alias TMUX='/usr/bin/tmux -2 -q -u attach-session || /usr/bin/tmux -2 -q -u'
# For GPG
GpgSign() { gpg --armor --detach-sign --yes --no-batch --use-agent "$@"; }
GpgVerify() { gpg --verify --no-batch --use-agent "$@"; }
function GpgEncrypt() { gpg --encrypt --yes --no-batch --use-agent -r "$EMAIL" "$@"; }
function GpgDecrypt() { gpg --decrypt --yes --no-batch --use-agent "$@"; }
# Pour que ssh-add ne memorise la passphrase que pendant 30 minutes
alias ssh-add='ssh-add -t 1800'
#alias youtube-dl="yt-dlp"
# youtube-dl shortcuts (there is also youtube-playlist.sh and youtube-albums.sh)
function youtube() {
for i in "$@"; do
arg="$(echo -e "$i" | grep -o v%3D[a-zA-Z0-9_-]*%26 | sed s/v%3D// | sed s/%26// )"
if [ "X$arg" = "X" ]; then arg="$i"; fi
echo -e "${green}Launching youtube-dl on ${white}${u}${arg}${U} ${black}(with the good options to download ${cyan}video${black} and ${cyan}mp3${black}).${white}"
#youtube-dl --restrict-filenames --youtube-skip-dash-manifest --output "%(title)s.%(ext)s" --extract-audio --console-title --keep-video --audio-format=mp3 --no-overwrites -- "$arg"
yt-dlp --restrict-filenames --youtube-skip-dash-manifest --output "%(title)s.%(ext)s" --extract-audio --console-title --keep-video --audio-format=mp3 --no-overwrites -- "$arg"
done
}
function youtube-mp3() {
for i in "$@"; do
arg="$(echo -e "$i" | grep -o v%3D[a-zA-Z0-9_-]*%26 | sed s/v%3D// | sed s/%26// )"
if [ "X$arg" = "X" ]; then arg="$i"; fi
echo -e "${green}Launching youtube-dl on ${white}${u}${arg}${U} ${black}(with the good options to download just the ${cyan}mp3${black}).${white}"
#youtube-dl --restrict-filenames --youtube-skip-dash-manifest --format worst --output "%(title)s.%(ext)s" --extract-audio --console-title --audio-format=mp3 --no-overwrites -- "$arg"
yt-dlp --restrict-filenames --youtube-skip-dash-manifest --format worst --output "%(title)s.%(ext)s" --extract-audio --console-title --audio-format=mp3 --no-overwrites -- "$arg"
done
}
alias y='youtube-mp3'
function youtube-video() {
for i in "$@"; do
arg="$(echo -e "$i" | grep -o v%3D[a-zA-Z0-9_-]*%26 | sed s/v%3D// | sed s/%26// )"
if [ "X$arg" = "X" ]; then arg="$i"; fi
echo -e "${green}Launching youtube-dl on ${white}${u}${arg}${U} ${black}(with the good options to download just the ${cyan}video${black}).${white}"
#youtube-dl --restrict-filenames --youtube-skip-dash-manifest --output "%(title)s.%(ext)s" --console-title --no-overwrites -- "$arg"
yt-dlp --restrict-filenames --youtube-skip-dash-manifest --output "%(title)s.%(ext)s" --console-title --no-overwrites -- "$arg"
done
}
alias getmod='/usr/bin/stat -c "%a"'
alias watch='watch -b -d -e'
# Do a job, only for a certain amount of time
# Exemple : DoForATime 60 my-very-long-command-that-can-never-terminate
function DoForATime() {
log="/tmp/DoForATime$(date "+%Hh-%Mm-%Ss").log"
TIMEOUT="$1"
shift
echo -e "${reset}Launching $@, in $PWD, for $TIMEOUT seconds only." | tee "$log"
echo -e "$white"
"$@" & { sleep "${TIMEOUT}"; eval 'kill -9 $!' &>> "$log"; }
}
function pstree() { /usr/bin/pstree -a -h -s -c -U "$@"; }
function sshtmux() {
if [ "Z$TMUX" = "Z" ]; then
echo -e "${blue}Using tmux on remote server.$white"
( /usr/bin/ssh -X -C -t "$@" "tmux -2 -q -u attach-session || byobu || tmux -2 -q -u" ) || ( alert ; echo -e "${red}Error, connection to $@ closed." )
else
echo -e "${red}Not using tmux on remote server. Unset \$TMUX to force this.$white"
/usr/bin/ssh -X -C -t "$@" || ( alert ; echo -e "${red}Error, connection to $@ closed." )
fi
}
# ssh shortcuts
alias sshzamok='sshtmux besson@zamok.crans.org'
alias sz='sshzamok'