dotfiles/scripts.org

12 KiB

#+title:General-Use Scripts

GUI-ish

  • Glue scripts for sxhkd / bspwm / polybar

Dmenu_run_top

  • Dmenu configured how I like it

TODO

  • test monospace instead of bitstream
  • remove flavours placeholder (once flavours is ready)
  • consider moving this to an alias
  <<sh-shebang()>>

  dmenu_run \
    -i \
    -fn BitstreamVeraSansMono:size=11 \
    -l 15 \
    -nf "$norm_fg" \
    -nb "$norm_bg" \
    -sf "$sel_fg" \
    -sb "$sel_bg"

Dmenuunicode

  • Get emojis from dmenu

TODO

  • make work on mac
  • recreate the emojis file and test
  <<sh-shebang()>>

  # Get user selection via dmenu from emoji file.
  chosen=$(cut -d ';' -f1 ~/.local/share/emoji | dmenu -i -l 30 | sed "s/ .*//")

  # Exit if none chosen.
  [ -z "$chosen" ] && exit

  # If you run this command with an argument, it will automatically insert the
  # character. Otherwise, show a message that the emoji has been copied.
  if [ -n "$1" ]; then
          xdotool type "$chosen"
  else
          printf "$chosen" | xclip -selection clipboard
          notify-send "'$chosen' copied to clipboard." &
  fi

Languagecycle

  • Cycle between a couple languages
  • Better handled through polybar probably

TODO

  • Add support for 3+ languages
  <<fish-shebang()>>

  if [ (xkblayout-state print "%n") = "Russian" ]
          setxkbmap -layout us
      else
          setxkbmap -layout ru
      end

Layoutcycle

  • Cycle windows between different layouts

TODO

  • Currently this adds layouts to an endless list of layouts which can cause lag
  • This should be fixed but I'm not sure if I even like using alternate layouts
  <<fish-shebang()>>

  bsp-layout next --layouts tall,grid,rgrid,tiled

  set layout (bsp-layout get)

  if ps -aux | grep layoutcycle | grep -v grep
      exit
  else if [ $layout = "tall" ]
      notify-send -t 1000 "Layout: Tall" (echo \
      "    ______________   \n" \
      "   |        |____|   \n" \
      "   |        |____|   \n" \
      "   |        |____|   \n" \
      "   |________|____|   " )
  else if [ $layout = "grid" ]
      notify-send -t 1000 "Layout: hGrid" (echo \
      "   ____________   \n" \
      "  |   |   |   |   \n" \
      "  |___|___|___|   \n" \
      "  |   |   |   |   \n" \
      "  |___|___|___|   " )
  else if [ $layout = "rgrid" ]
     vgrid
      notify-send -t 1000 "Layout: vGrid" (echo \
      "   ____________   \n" \
      "  |_____|_____|   \n" \
      "  |_____|_____|   \n" \
      "  |_____|_____|   " )
  else if [ $layout = "tiled" ]
      notify-send -t 1000 "Layout: Tiled" (echo \
      "   ______________   \n" \
      "  |        |    |   \n" \
      "  |        |____|   \n" \
      "  |        |  | |   \n" \
      "  |________|__|_|   " )
  end

Appearance

Colors

> Taken from https://stackoverflow.com/questions/69138165/how-to-get-the-rgb-values-of-a-256-color-palette-terminal-color

  • Returns a representation of your currently set color scheme
  <<sh-shebang()>>

  xdef="$HOME/.Xresources"

  colors=( $( sed -re '/^!/d; /^$/d; /^#/d; s/(\*color)([0-9]):/\10\2:/g;' $xdef | grep 'color[01][0-9]:' | sort | sed  's/^.*: *//g' ) )

  echo
  for i in {0..7}; do echo -en "\e[$((30+$i))m ${colors[i]} \u2588\u2588 \e[0m\n"; done
  echo
  for i in {8..15}; do echo -en "\e[1;$((22+$i))m ${colors[i]} \u2588\u2588 \e[0m\n"; done
  echo -e "\n"

Themepick

  • Broken in nix until I find an equivalent base16 theme setter and / or setup flavours
  <<fish-shebang()>>
  set theme (flavours list | tr ' ' '\n' | dmenu)

  flavours apply $theme &&
  eval ~/.config/base16-shell/scripts/base16-$theme.sh

Opaque-windows

TODO

  • Handle this through lemonbar instead
  <<fish-shebang()>>
  if ps -aux | grep picom | grep -v grep
      pkill picom
  end

Transparent-windows

  <<fish-shebang()>>

  if ps -aux | grep picom | grep -v grep
      pkill picom
  end

  sleep 0.2
  picom \
      --conf /dev/null \
      -i 0. \
      --active-opacity 1.0 \
      --focus-exclude "x = 0 && y = 0 && override_redirect = true" &

Password Management

  • Some basic scripts to help gnu password-store suit my preferences

Generate-passphrase

  • Generates a pseudo-random CorrectHorseBatteryStaple-style password

    • I prefer this for passwords I might have to type manually occasionally

TODO

  • This may be better as an alias
  <<bash-shebang()>>
  shuf -n3 /usr/share/dict/words | tr -d '\n'

Passphrase

  • This more specifically inserts the generated passphrase into gnu pass
  <<fish-shebang()>>
  generate-passphrase | pass insert -e $argv

Git

Prune_local_branches

TODO

  • Don't do this. Use a git alias.
  <<bash-shebang()>>
  git fetch --all -p; git branch -vv | grep ": gone]" | awk '{ print $1 }' | xargs -r -n 1 git branch -D

APIs

Sugar

  • Get blood sugar from nightscout

    • Useful for gui integrations

TODO

  • Remove lemobar, test with polybar
  • Handle API endpoint as a secret
  <<python-shebang()>>

  import sys
  import requests
  import json
  from termcolor import colored

  tmux = '--tmux' in sys.argv
  lemonbar = '--lb' in sys.argv

  down = '\u2193'     # ↓
  falling = '\u2798'  # ➘
  flat = '\u2192'     # →
  rising = '\u279a'   # ➚
  up = '\u2191'       # ↑

  url = # TODO interpolate or parameterize
  options = '/api/v1/entries.json?count=1&token=phone-7631d7eebc79825b'

  try:
      res = requests.get(url + options)
  except:
      sys.exit()

  sugar = res.json()[0]

  delta = sugar['delta']
  sgv = sugar['sgv']
  direction = sugar['direction']

  if delta < -10:
      arrow = down
  if delta >= -10 and delta < -1:
      arrow = falling
  if delta >= -1 and delta <= 1:
      arrow = flat
  if delta > 1 and delta <= 10:
      arrow = rising
  if delta > 10:
      arrow = up

  if (sgv >= 225 or sgv <= 80):
      color = 'red'
  elif ((sgv >= 180 and sgv <= 225)
          or (sgv <= 100 and sgv >= 80)):
      color = 'yellow'
  else:
      color = 'green'

  if tmux:
      print(f'#[bg={color}] ' +
          str(round(sugar['sgv'], 1)) + ' ' +
          arrow + ' ' +
          '(' + str(delta) + ')'
          )
  elif lemonbar:
      print(str(round(sugar['sgv'], 1)) + ' ' +
            arrow + ' ' +
            '(' + str(delta) + ')'
          )
  else:
      print(colored(str(sugar['sgv']) +
                  ' ' + arrow + ' ' +
                  '(' + str(delta) + ')',
                  color))

Mac-specific

Jbrowse

TODO

  • Probably handle these as aliases
/Applications/Brave\ Browser.app/Contents/MacOS/Brave\ Browser "https://everblue.atlassian.net/browse/"$1 &

NotifyMe

osascript -e 'display notification "done!" with title "Notification"'

#!/bin/sh

  <<sh-shebang()>>

  dmenu_run \
    -i \
    -fn BitstreamVeraSansMono:size=11 \
    -l 15 \
    -nf "$norm_fg" \
    -nb "$norm_bg" \
    -sf "$sel_fg" \
    -sb "$sel_bg"

Dmenuunicode

  • Get emojis from dmenu

TODO

  • make work on mac
  • recreate the emojis file and test
  <<sh-shebang()>>

  # Get user selection via dmenu from emoji file.
  chosen=$(cut -d ';' -f1 ~/.local/share/emoji | dmenu -i -l 30 | sed "s/ .*//")

  # Exit if none chosen.
  [ -z "$chosen" ] && exit

  # If you run this command with an argument, it will automatically insert the
  # character. Otherwise, show a message that the emoji has been copied.
  if [ -n "$1" ]; then
          xdotool type "$chosen"
  else
          printf "$chosen" | xclip -selection clipboard
          notify-send "'$chosen' copied to clipboard." &
  fi

Languagecycle

  • Cycle between a couple languages
  • Better handled through polybar probably

TODO

  • Add support for 3+ languages
  <<fish-shebang()>>

  if [ (xkblayout-state print "%n") = "Russian" ]
          setxkbmap -layout us
      else
          setxkbmap -layout ru
      end

Layoutcycle

  • Cycle windows between different layouts

TODO

  • Currently this adds layouts to an endless list of layouts which can cause lag
  • This should be fixed but I'm not sure if I even like using alternate layouts
  <<fish-shebang()>>

  bsp-layout next --layouts tall,grid,rgrid,tiled

  set layout (bsp-layout get)

  if ps -aux | grep layoutcycle | grep -v grep
      exit
  else if [ $layout = "tall" ]
      notify-send -t 1000 "Layout: Tall" (echo \
      "    ______________   \n" \
      "   |        |____|   \n" \
      "   |        |____|   \n" \
      "   |        |____|   \n" \
      "   |________|____|   " )
  else if [ $layout = "grid" ]
      notify-send -t 1000 "Layout: hGrid" (echo \
      "   ____________   \n" \
      "  |   |   |   |   \n" \
      "  |___|___|___|   \n" \
      "  |   |   |   |   \n" \
      "  |___|___|___|   " )
  else if [ $layout = "rgrid" ]
     vgrid
      notify-send -t 1000 "Layout: vGrid" (echo \
      "   ____________   \n" \
      "  |_____|_____|   \n" \
      "  |_____|_____|   \n" \
      "  |_____|_____|   " )
  else if [ $layout = "tiled" ]
      notify-send -t 1000 "Layout: Tiled" (echo \
      "   ______________   \n" \
      "  |        |    |   \n" \
      "  |        |____|   \n" \
      "  |        |  | |   \n" \
      "  |________|__|_|   " )
  end