Files
literate-dotfiles/binaries-laptop.org

5.1 KiB

Binaries specific to my ESRF Laptop

phonebook ESRF phone-book

Old phonebook: The phone-list is taken from scp rnice@esrf.fr:/mnt/multipath-shares/sware/pub/phonelist/share/annuaire.txt /home/thomas/.local/data/annuaire.txt new phonebook: Use the etd script

cat ~/.local/data/annuaire.txt | fzf --header="NAME                         Surname               Phone    Office              Room        Email"
$TERMINAL --title esrf-phonebook -e phonebook
#!/bin/bash

ROOT_URL='https://phonedirectory.esrf.fr'
API_ENDPOINT="$ROOT_URL/api"
USAGE="
  ESRF Telephone Directory

  CLI to search $ROOT_URL

  Usage :
    # Search for <search term> in first name or last name
    $0 <search term>

"

function fail {
  echo "$1" >&2
  exit 1
}

function json_curl { curl --get --fail --silent --show-error -H "Content-Type:application/json" -H "Accept: application/json" "$@"; }

function lspersons {
    # List users and output result in csv
    json_curl --data-urlencode "search=$1" "$API_ENDPOINT/searchUsers" |\
      jq -r '. | (map(keys) | add | unique | sort) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $rows[] | @csv' 2>/dev/null
}

if [ $# -eq 0 ]; then
  fail "$USAGE"
fi

# Print the list of persons as a table

lspersons $1 | awk 'BEGIN { FS=OFS="," }; {print $4,$3,$5,$1,$6,$2,$7}' | sed 's/"//g' | column -t -s "," | sort

exit $?

contacts Personnal phone-book

khard | fzf --header="Index    Name                      Phone                       E-Mail"
$TERMINAL --title esrf-phonebook -e contacts

wake-on-lan - Wake on LAN

computer=$(echo -e 'ZOTAC' | rofi -i -dmenu -p 'Computer:' -l 20);

if [[ -z "$computer" ]]; then
    exit 1
fi

dunstify --replace=99425 'Wake On Lan' "${computer}..."

case "$computer" in
    "ZOTAC")
        ssh homelab 'wakeonlan 00:01:2E:A2:42:9C' ;;

esac

screen-select - Xrandr pre-defined scripts

option=$(echo -e "Work\nLaptop\nHome\nAouste" | rofi -i -dmenu -no-custom -p 'Screen:' -l 20)

if [[ -z "$option" ]]; then
    exit 1
fi

after_screen_change () {
    # Fix background if screen size/arangement has changed.
    setbg

    # Kill polybar
    killall -q polybar

    # Wait until the processes have been shut down
    while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done

    # Launch bars
    polybar top &
}

case "$option" in
    "Work")
        xrandr --output eDP-1 --off \
               --output DP-3-2 --primary --mode 2560x1440 --pos 0x0    --rotate normal \
               --output DP-3-1 --primary --mode 2560x1440 --pos 2560x0 --rotate normal && \
               after_screen_change
        ;;
    "Laptop")
        xrandr --output DP-1-1 --off \
               --output DP-1-2 --off \
               --output DP-3-1 --off \
               --output DP-3-2 --off \
               --output HDMI-1 --off \
               --output eDP-1 --primary --mode 1920x1200 --pos 0x0 --rotate normal && \
               after_screen_change
        ;;
    "Home")
        xrandr --output eDP-1  --off \
               --output DP-3-1 --off \
               --output DP-3-2 --off \
               --output HDMI-1 --off \
               --output DP-1-2 --primary --mode 2560x1440 --pos 0x0 --rotate normal && \
               after_screen_change
        ;;
    "Aouste")
        xrandr --output eDP-1 --off \
               --output HDMI-1 --primary --mode 2560x1440 --pos 0x0 --rotate normal && \
               after_screen_change
        ;;
    ,*)
        echo "== ! missing or invalid argument ! =="
        exit 2
esac

exit 0

print-esrf - Print on Rnice

  • To list printers lpstat -p -d
nbpage=$(echo -e '1\n2\n4' | rofi -dmenu -no-custom -p 'Number of pages per sheet' -l 20);
sides=$(echo -e 'one-sided\ntwo-sided-long-edge\ntwo-sided-short-edge' | rofi -dmenu -no-custom -p 'Two Sided:' -l 20);
media=$(echo -e 'A4\nA3' | rofi -dmenu -no-custom -p 'Size:' -l 20);
printer=$(echo -e 'ctb127c1u\nctb110c1u' | rofi -dmenu -no-custom -p 'Size:' -l 20);

if [[ -z "$nbpage" || -z "$sides" || -z "$media" || -z "$printer" ]]; then
    exit 1
fi

rsync -zaP "$1" dehaeze@rnice:/home/esrf/dehaeze/Downloads/to-be-printed.pdf && \
    ssh rnice "lpr -o media=$media -o sides=$sides -o number-up=$nbpage -P $printer /home/esrf/dehaeze/Downloads/to-be-printed.pdf";