utilies

A handful of (useful) scripts for unix-like systems
Log | Files | Refs | README | LICENSE

commit 8dc5497aabb803e24ccf604689a3523b144bd484
parent 66013619b874a208ee75e43b9144a8ad0d336b54
Author: Rikard Karlsen <rk@cassettian.space>
Date:   Thu, 26 Aug 2021 20:31:14 +0200

feat: add scripts

Diffstat:
Aaddscript | 13+++++++++++++
Abrøkur | 32++++++++++++++++++++++++++++++++
Acrypto | 16++++++++++++++++
Adiscotime | 6++++++
Adiskspace-usage | 3+++
Alemonblocks | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alemonblocks-reload | 6++++++
Alockscreen | 5+++++
Aminuttvarsel | 6++++++
Areloadwm | 19+++++++++++++++++++
Asetwallpaper | 6++++++
Asnapcam | 3+++
Aspv | 23+++++++++++++++++++++++
Avolumkontroll | 31+++++++++++++++++++++++++++++++
Axkbutil | 23+++++++++++++++++++++++
15 files changed, 307 insertions(+), 0 deletions(-)

diff --git a/addscript b/addscript @@ -0,0 +1,13 @@ +#!/bin/sh + +[ "$1" = "" ] && echo "Need name of script" && exit 1 + +_filename="$HOME/.local/bin/$1" + +[ -f "$_filename" ] && nvim "$_filename" && exit + +touch "$_filename" +chmod +x "$_filename" +echo -e "#! /bin/sh\n\n" > "$_filename" +nvim "$_filename" + diff --git a/brøkur b/brøkur @@ -0,0 +1,32 @@ +#!/bin/sh + +m="$(date '+%_M' | tr -d ' ')" + +if [ $m -lt "5" ]; then + M="" +elif [ $m -lt "13" ]; then + M="⅙" +elif [ $m -lt "18" ]; then + M="¼" +elif [ $m -lt "25" ]; then + M="⅓" +elif [ $m -lt "35" ]; then + M="½" +elif [ $m -lt "43" ]; then + M="⅓" +elif [ $m -lt "48" ]; then + M="¼" +elif [ $m -lt "55" ]; then + M="⅙" +else + M="" +fi + +if [ $m -gt "24" ]; then + h="$(date -d "1 hour" '+%_I' | tr -d ' ')" + echo "$M$h" +else + h="$(date '+%_I' | tr -d ' ')" + echo "$h$M" +fi + diff --git a/crypto b/crypto @@ -0,0 +1,16 @@ +#! /bin/sh + +_configfile="$XDG_CONFIG_HOME/cryptorc" + +alias config_not_exists\?="[ ! -x $_configfile ]" +alias source_config=". $_configfile" +alias exit_with_error="echo 'ERROR: Config file nonexistent or not executable.' && exit" + +config_not_exists? && exit_with_error || source_config + +alias get="curl -s 'http://$currency.rate.sx/$amount'" +alias floor="cut -d. -f1" +alias xprint="xargs printf '%s kr\n'" + +get | floor | xprint + diff --git a/discotime b/discotime @@ -0,0 +1,6 @@ +#! /bin/sh + +mpv "https://www.youtube.com/playlist?list=PL8RuAUpRy-Eo6N1zMN196VofrLJTG4XmJ" \ + --no-video \ + --player-operation-mode=pseudo-gui + diff --git a/diskspace-usage b/diskspace-usage @@ -0,0 +1,3 @@ +#! /bin/sh +du -hd1 -BM "$1" | sort -hr + diff --git a/lemonblocks b/lemonblocks @@ -0,0 +1,115 @@ +#!/bin/sh + +_desktops() { + #desktops=$(bspc query -D --names) + active_desktop=$(bspc query -D -d --names) + for d in $(bspc query -D -m --names); do + [ $active_desktop = $d ] && item="%{R} $d %{R}" || item=" $d " + ret="$ret$item" + done + echo "$ret " +} + +_keymap() { + cat "$XDG_CONFIG_HOME/keymaps/current-layout" +} + +_window_title() { + echo "" +} + +# mute icon: \uf6a9 +_volume() { + _vol_info=$(amixer sget Master | grep "Front Left:") + _vol=$(echo $_vol_info | awk '{print $5}' | tr -d "[]%")% + [ "$(echo $_vol_info | awk '{print $7}')" = "[off]" ] && _vol="M" + echo -e " V$_vol " +} + +_battery() { + batinfo=$(acpi --battery) + BATPERC=B$(echo $batinfo | cut -d, -f2 | cut -d" " -f2 | cut -d% -f1) + state=$(echo $batinfo | awk '{print $3}' | cut -d, -f1) + + bat=" $BATPERC% " + + if [ "$state" = "Discharging" ]; then + [ "$BATPERC" = "15" ] && notify-send --urgency=low "Lavt batteri!" "15%" + [ "$BATPERC" = "10" ] && notify-send --urgency=normal "Veldig lavt batteri!" "10%" + [ "$BATPERC" -lt "6" ] && notify-send --urgency=critical "Ektremt lavt batteri!" "$BATPERC%" + + if [ "$BATPERC" -lt "11" ]; then + bat="%{B#ff0000} $BATPERC% %{B-}" + elif [ "$BATPERC" -lt "41" ]; then + bat="%{B#ffff00}%{F#000000} $BATPERC% %{F-}%{B-}" + fi + elif [ "$state" = "Full" ]; then + bat="%{B#00ff00}%{F#000000} $BATPERC% %{F-}%{B-}" + fi + + echo "$bat" +} + +_clock() { + #DATETIME=$(date "+%A %d. %B %Y - %I:%M") + #DATETIME=$(date "+%-I:%-M") + #DATETIME=$(ordur) + DATETIME=$(brøkur) + echo "$DATETIME" +} + +_window_title() { + _title=`bspc query --node focused.window -T | jq ".client.className"` + _title="${_title%\"}" + _title="${_title#\"}" + echo "$_title" +} + +_update() { + echo -e "%{l}$desks%{c}$(_clock)%{r}$keym%{R} $vol %{R}$(_battery)" & + wait +} + +_update_desktops() { + desks=$(_desktops) + _update +} + +_update_volume() { + vol=$(_volume) + _update +} + +_update_keymap() { + keym=" $(_keymap) " + _update +} + +_update_window_title() { + #while true; do + win_title=" $(_window_title) " + _update + # sleep 1s + # wait + #done +} + +_update_desktops > /dev/null +_update_volume > /dev/null +_update_keymap > /dev/null +# _update_window_title > /dev/null + +_lemonblocks() { + trap "_update_desktops" SIGRTMIN+1 + trap "_update_volume" SIGRTMIN+2 + trap "_update_keymap" SIGRTMIN+3 + + while true; do + _update + sleep 1m & + wait + done +} + +_lemonblocks | lemonbar -p -g x24 -B "#44111111" -F "#FFFFFF" -f "Go:size=10" | $SHELL + diff --git a/lemonblocks-reload b/lemonblocks-reload @@ -0,0 +1,6 @@ +#!/bin/sh + +[ "$1" = "desktops" ] && pkill -SIGRTMIN+1 lemonblocks +[ "$1" = "volume" ] && pkill -SIGRTMIN+2 lemonblocks +[ "$1" = "keymap" ] && pkill -SIGRTMIN+3 lemonblocks + diff --git a/lockscreen b/lockscreen @@ -0,0 +1,5 @@ +#!/bin/sh + +img="$XDG_DATA_HOME/backweb/img.png" + +[ -f "$img" ] && i3lock -ei "$img" diff --git a/minuttvarsel b/minuttvarsel @@ -0,0 +1,6 @@ +#!/bin/sh + +while :; do + sleep 1m + notify-send "Un minuto" +done diff --git a/reloadwm b/reloadwm @@ -0,0 +1,19 @@ +#!/bin/sh + +# WM +bspc wm -r + +# Backweb-skript +#pkill backweb && backweb & + +# Sxhkd +pkill -USR1 -x sxhkd + +# Lemonbar +pkill polybar + +# Set wallpaper +xwallpaper --zoom ~/.config/wallpaper & + +#xdo above -t $(xdo id -n root) $(xdo id -n lemonbar) + diff --git a/setwallpaper b/setwallpaper @@ -0,0 +1,6 @@ +#!/bin/sh + +[ -n "$1" ] && img=`realpath $1` || img=`sxiv $HOME/img/* -ot | head -n 1` + +ln -sf "$img" ~/.config/wallpaper +xwallpaper --zoom ~/.config/wallpaper diff --git a/snapcam b/snapcam @@ -0,0 +1,3 @@ +#!/bin/sh + +mpv --demuxer-lavf-format=video4linux2 --demuxer-lavf-o-set=input_format=mjpeg av://v4l2:/dev/video0 --profile=low-latency --untimed diff --git a/spv b/spv @@ -0,0 +1,23 @@ +#!/bin/bash + +# Search Play Video + +[ "$1" != "" ] && query="$@" || query=`rofi -dmenu -p "Finn video" -lines 0` +[ "$query" = "" ] && exit 1 + +# json=`youtube-dl ytsearch:"$query" -x - | sed 1q` +json=`youtube-dl ytsearch:"$query" -j` + +title=`echo $json | jq ".title"` +url=`echo $json | jq ".formats | map(select(.vcodec==\"none\")) | .[-1].url"` +channel=`echo $json | jq ".uploader"` + +_trimquotes () { + temp="${1%\"}" + echo "${temp#\"}" +} + +notify-send "`_trimquotes "$title"`" "`_trimquotes "$channel"`" + +mpv "`_trimquotes "$url"`" + diff --git a/volumkontroll b/volumkontroll @@ -0,0 +1,31 @@ +#!/bin/sh + +_toggle() { + if [ "$(pulsemixer --get-mute)" = "1" ]; then + pulsemixer --unmute + else + pulsemixer --mute + fi +} + +_change() { + pulsemixer --change-volume "$1" +} + +_set() { + pulsemixer --set-volume "$1" +} + +_print() { + vol=$(pulsemixer --get-volume | awk '{print $1}') + [ "$(pulsemixer --get-mute)" = "1" ] && vol="M" + echo "$vol%" +} + +[ "$1" = "" ] && _print && exit +[ "$1" = "toggle" ] && _toggle +[ "$1" = "change" ] && [ "$2" != "" ] && _change "$2" +[ "$1" = "set" ] && [ "$2" != "" ] && _set "$2" + +[ "$WM" = "i3" ] && pkill -RTMIN+10 i3blocks + diff --git a/xkbutil b/xkbutil @@ -0,0 +1,23 @@ +#!/bin/sh + +dir=$XDG_CONFIG_HOME/keymaps + +_set () { + xkbcomp "$dir/$1.xkbmap" $DISPLAY && echo "$1" > "$dir/current-layout" +} + +_toggle() { + if [ -f "$dir/current-layout" ]; then + layout="$(cat $dir/current-layout)" + case $layout in + "NO") _set "RU";; + "RU") _set "NO";; + esac + fi +} + +[ "$1" = "toggle" ] && _toggle && exit 0 +[ "$1" = "set" ] && [ "$2" != "" ] && _set "$2" && exit 0 + +echo "Usage: xkbutil [toggle|set layout]" +