From b57650cced837dd2783369ad49e16806051b894e Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Mon, 9 May 2022 10:06:19 +0200 Subject: [PATCH] Add nice binaries --- bash.org | 1 + binaries-private.org | 78 +++++++++++++++++++++++++---- binaries.org | 114 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+), 9 deletions(-) diff --git a/bash.org b/bash.org index ca529df..8185a99 100644 --- a/bash.org +++ b/bash.org @@ -86,6 +86,7 @@ alias grep='grep --colour=auto' alias cp="cp -i" # confirm before overwriting something alias df='df -h' # human-readable sizes alias free='free -m' # show sizes in MB +alias bat='batcat' alias mutt="neomutt" alias tmux='tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf' #+END_SRC diff --git a/binaries-private.org b/binaries-private.org index e9df852..74f77a3 100644 --- a/binaries-private.org +++ b/binaries-private.org @@ -5,6 +5,34 @@ #+PROPERTY: header-args:bash+ :shebang "#!/usr/bin/env bash" #+PROPERTY: header-args:bash+ :tangle-mode (identity #o555) +* =phonebook= ESRF phone-book +:PROPERTIES: +:CUSTOM_ID: phonebook +:END: + +The phone-list is taken from =scp opid21@lid21nano:/mnt/multipath-shares/sware/pub/phonelist/share/annuaire.txt /home/thomas/.local/data/annuaire.txt= + +#+begin_src bash :tangle ~/.local/bin/phonebook +cat ~/.local/data/annuaire.txt | fzf --header="NAME Phone Box department roomNumber description mail" +#+end_src + +#+begin_src bash :tangle ~/.local/bin/phonebook-gui +$TERMINAL --title esrf-phonebook -e phonebook +#+end_src + +* =contacts= Personnal phone-book +:PROPERTIES: +:CUSTOM_ID: contacts +:END: + +#+begin_src bash :tangle ~/.local/bin/contacts +khard | fzf --header="Index Name Phone E-Mail" +#+end_src + +#+begin_src bash :tangle ~/.local/bin/contacts-gui +$TERMINAL --title esrf-phonebook -e contacts +#+end_src + * =qutebrowser= :PROPERTIES: :CUSTOM_ID: qutebrowser @@ -14,13 +42,26 @@ ~/.local/soft/qutebrowser/.venv/bin/python3 -m qutebrowser "$@" #+end_src +* =remote-home= - Remote Desktop to Home PC +:PROPERTIES: +:CUSTOM_ID: remote-home +:END: + +#+begin_src bash :tangle ~/.local/bin/remote-home +notify-send 'Rdesktop' "Connection to Home PC..." + +common_arg="/clipboard /bpp:8 /bpp:16 /compression -themes -wallpaper /async-update /async-input -glyph-cache /audio-mode:1 /dynamic-resolution /auto-reconnect /wm-class:RDP_PC /grab-keyboard /cert:ignore" + +xfreerdp $common_arg /u:thomas /p:$(pass home_pc/thomas | sed -n 1p) /v:192.168.1.72 > /tmp/freerdp_home_pc.log 2>&1 & +#+end_src + * =remote-desktop= - Remote Desktop Connect :PROPERTIES: :CUSTOM_ID: remote-desktop :END: #+begin_src bash :tangle ~/.local/bin/remote-desktop -computer=$(echo -e 'WID21SPEEDGOAT1\nWID24SPEEDGOAT1\nPCMEL1\nRNICE\nPCDEHAEZE\nPCNASS1' | rofi -dmenu -no-custom -p 'Computer:' -l 20); +computer=$(echo -e 'WID21SPEEDGOAT1\nWBM23SPEEDGOAT1\nWID24SPEEDGOAT1\nPCMEL1\nRNICE\nPCDEHAEZE\nLAPPAMU1\nPCNASS1\nDesktop-W10' | rofi -i -dmenu -no-custom -p 'Computer:' -l 20); if [[ -z "$computer" ]]; then exit 1 @@ -29,22 +70,40 @@ fi notify-send 'Rdesktop' "Connection to ${computer}..." proxy_arg="" -if [ -z "$(timeout 1s dig +short proxy.esrf.fr.)" ]; then - proxy_arg="/proxy:socks5://localhost:8080" +if [ "$computer" = "Desktop-W10" ]; then + # If connect to local PC + if [ ping -c 1 -t 1 desktop-w10.lan &> /dev/null ]; then + # And outside of local network, use proxy + proxy_arg="/proxy:socks5://localhost:8080" + fi +elif [ -z "$(timeout 1s dig +short proxy.esrf.fr.)" ]; then + # Outside the ESRF network + proxy_arg="/proxy:socks5://localhost:8081" fi +common_arg="/clipboard /bpp:8 /bpp:16 /compression -themes -wallpaper /async-update /async-input -glyph-cache /audio-mode:1 /dynamic-resolution /auto-reconnect /wm-class:RDP_$computer /grab-keyboard /cert:ignore" + case "$computer" in "RNICE" | "PCDEHAEZE" | "PCNASS1") - xfreerdp $proxy_arg /u:dehaeze /d:ESRF /clipboard /bpp:8 /bpp:16 /compression -themes -wallpaper /async-update /async-input -glyph-cache /audio-mode:1 /dynamic-resolution /auto-reconnect /wm-class:RDP_$computer /grab-keyboard /p:$(pass esrf.fr/dehaeze | sed -n 1p) /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; + xfreerdp $proxy_arg $common_arg /d:ESRF /u:dehaeze /p:$(pass esrf.fr/dehaeze | sed -n 1p) /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; "PCMEL1") - xfreerdp $proxy_arg /u:OPPEL /d:ESRF /clipboard /bpp:8 /bpp:16 /compression -themes -wallpaper /async-update /async-input -glyph-cache /audio-mode:1 /dynamic-resolution /auto-reconnect /wm-class:RDP_$computer /grab-keyboard /p:TonicPEL /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; + xfreerdp $proxy_arg $common_arg /d:ESRF /u:OPPEL /p:TonicPEL /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; "WID21SPEEDGOAT1") - xfreerdp $proxy_arg /u:opid21 /d:ESRF /clipboard /bpp:8 /bpp:16 /compression -themes -wallpaper /async-update /async-input -glyph-cache /audio-mode:1 /dynamic-resolution /auto-reconnect /wm-class:RDP_$computer /grab-keyboard /p:tonic21 /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; + xfreerdp $proxy_arg $common_arg /d:ESRF /u:opid21 /p:tonic21 /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; + + "WBM23SPEEDGOAT1") + xfreerdp $proxy_arg $common_arg /d:ESRF /u:opd23 /p:tonic23 /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; "WID24SPEEDGOAT1") - xfreerdp $proxy_arg /u:opid24 /d:ESRF /clipboard /bpp:8 /bpp:16 /compression -themes -wallpaper /async-update /async-input -glyph-cache /audio-mode:1 /dynamic-resolution /auto-reconnect /wm-class:RDP_$computer /grab-keyboard /p:tonic24 /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; + xfreerdp $proxy_arg $common_arg /d:ESRF /u:opid24 /p:tonic24 /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; + + "LAPPAMU1") + xfreerdp $proxy_arg $common_arg /d:ESRF /u:opid00 /p:tonic00 /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;; + + "Desktop-W10") + xfreerdp $proxy_arg $common_arg /d:ESRF /u:thomas /p:$(pass windows/Desktop-W10 | sed -n 1p) /v:192.168.1.72 > /tmp/freerdp_${computer}.log 2>&1 & ;; esac #+end_src @@ -72,7 +131,7 @@ dehaeze@rnice:/home/esrf/dehaeze/ /home/thomas/mnt/unix_home fuse.sshfs no #+begin_src bash :tangle ~/.local/bin/mount-dir if [ $# -eq 0 ]; then - drive=$(echo -e 'tmp_14_days\nhomelab\ngroupshare\nunix_home\ndata_id21' | rofi -dmenu -no-custom -p 'Drive:' -l 20); + drive=$(echo -e 'monochromators\ntmp_14_days\nhomelab\ngroupshare\nunix_home\ndata_id21' | rofi -dmenu -no-custom -p 'Drive:' -l 20); if [[ -z "$drive" ]]; then exit 1 fi @@ -125,7 +184,7 @@ case "$option" in after_screen_change ;; "Laptop") - xrandr --output DP-1-2 --off --output eDP-1 --primary --mode 1920x1200 --pos 0x0 --rotate normal && \ + xrandr --output DP-1-2 --off --output DP-3-2 --off --output eDP-1 --primary --mode 1920x1200 --pos 0x0 --rotate normal && \ after_screen_change ;; "Home") @@ -179,3 +238,4 @@ List all =pdf= files and open selected one with zathura. #+begin_src bash :tangle ~/.local/bin/readnotes cd ~/Cloud/brain/pdfs/ && ls *.pdf | rofi -dmenu -lines 20 | xargs -I {} zathura {} #+end_src + diff --git a/binaries.org b/binaries.org index 6b059d4..9dfc516 100644 --- a/binaries.org +++ b/binaries.org @@ -1102,6 +1102,79 @@ case "$in_ext" in esac #+end_src +* =preview-file= - Preview any file +:PROPERTIES: +:CUSTOM_ID: preview-file +:header-args: :tangle ~/.local/bin/preview-file +:END: +** Get basic information about the file +#+begin_src bash +# Get filename +filename_with_extension=$(basename -- "$1") +# Extract extension of the file +in_ext="${filename_with_extension##*.}" +# filename without extension +filename_without_extension=${filename_with_extension%.*} +#+end_src + +** SVG files + +#+begin_src bash +# Convert SVG Files +svg2() { \ + if command -v inkscape &> /dev/null; then + inkscape --export-type="$out_ext" "$filename_with_extension" --export-filename="/tmp/$filename_without_extension.pdf" && zathura "/tmp/$filename_without_extension.pdf" + fi +} +#+end_src + +** DOCX files + +#+begin_src bash +# Convert DOCX/PPTX Files +docx2() { \ + if command -v lowriter &> /dev/null; then + lowriter --convert-to pdf "$filename_with_extension" --outdir /tmp/ && zathura "/tmp/$filename_without_extension.pdf" + fi +} +#+end_src + +** Case statement +#+begin_src bash +case "$in_ext" in + "svg") + svg2 + ;; + "gif") + gif2 + ;; + "dvi") + dvi2 + ;; + "pdf") + pdf2 + ;; + "mp4") + mp42 + ;; + "png") + png2 + ;; + "jpg") + jpg2 + ;; + "jpeg") + jpg2 + ;; + "docx") + docx2 + ;; + "pttx") + docx2 + ;; +esac +#+end_src + * =pdf-shrink= - Pdf Shrink :PROPERTIES: :CUSTOM_ID: pdf-shrink @@ -1257,3 +1330,44 @@ awk '/^[a-z]/ && last {print "",$0,"\t",last,""} {last=""} /^#/{l column -t -s $'\t' | rofi -dmenu -i -markup-rows -no-show-icons -width 1000 -lines 15 -yoffset 40 #+end_src + +* =qrdecode= - Decode QRcode by taking screenshot + +- =zbar-tools= +- =main= +- =xclip= +- =notify-send= + +#+begin_src bash :tangle ~/.local/bin/qrdecode +image_file="/tmp/ocr.png" + +# Take screenshot by selecting the area +maim -s "$image_file" + +# Get the exit code of the previous command. +# So in this case, it is the screenshot command. If it did not exit with an +# exit code 0, then it means the user canceled the process of taking a +# screenshot by doing something like pressing the escape key +status=$? + +# If the user pressed the escape key or did something to terminate the proccess +# taking a screenshot, then just exit +[ $status -ne 0 ] && exit 1 + +# Use zbarimg to decode the text from the QR code +decoded_text=$(zbarimg "$image_file" -q --raw) + +if [ -z "$decoded_text" ]; then + notify-send "qrshot" "no text was detected" + rm $image_file && exit 1 +fi + +# Copy text to clipboard +printf %b "$decoded_text" | xclip -selection clip + +# Let us know that something was decoded +notify-send "qrshot" "$decoded_text" + +# Cleaning up the trash that was left behind +rm $image_file +#+end_src