From 401333b4ed1d1b73e2de17696d9bdfbef59dae5e Mon Sep 17 00:00:00 2001 From: Victor Timofei Date: Sat, 3 Jun 2023 15:15:49 +0300 Subject: [PATCH] Initial commit --- bt-restart | 6 ++ completion/docker-clear-log.bash | 13 ++++ completion/git-df.bash | 1 + docker-clear-log | 21 +++++++ docker-rm-all | 3 + docker-rm-images | 3 + get-layout | 13 ++++ getvol | 3 + laptopkb-disable | 8 +++ laptopkb-enable | 8 +++ laptopkb-get-id | 5 ++ laptoptouch-disable | 8 +++ laptoptouch-get-id | 3 + lock_screen | 3 + mutetog | 5 ++ poweroff | 7 +++ reboot | 7 +++ toggle-language | 18 ++++++ va2-capture | 105 +++++++++++++++++++++++++++++++ voldown | 5 ++ volinfo | 9 +++ volup | 5 ++ 22 files changed, 259 insertions(+) create mode 100755 bt-restart create mode 100644 completion/docker-clear-log.bash create mode 100644 completion/git-df.bash create mode 100755 docker-clear-log create mode 100755 docker-rm-all create mode 100755 docker-rm-images create mode 100755 get-layout create mode 100755 getvol create mode 100755 laptopkb-disable create mode 100755 laptopkb-enable create mode 100755 laptopkb-get-id create mode 100755 laptoptouch-disable create mode 100755 laptoptouch-get-id create mode 100755 lock_screen create mode 100755 mutetog create mode 100755 poweroff create mode 100755 reboot create mode 100755 toggle-language create mode 100755 va2-capture create mode 100755 voldown create mode 100755 volinfo create mode 100755 volup diff --git a/bt-restart b/bt-restart new file mode 100755 index 0000000..12e22bc --- /dev/null +++ b/bt-restart @@ -0,0 +1,6 @@ +#!/usr/bin/bash + +rfkill block bluetooth +rfkill unblock bluetooth +sudo systemctl stop bluetooth.service +sudo systemctl start bluetooth.service diff --git a/completion/docker-clear-log.bash b/completion/docker-clear-log.bash new file mode 100644 index 0000000..00ebdfd --- /dev/null +++ b/completion/docker-clear-log.bash @@ -0,0 +1,13 @@ +#/usr/bin/env bash + +_docker-clear-log() +{ + if [ "${#COMP_WORDS[@]}" != "2" ]; then + return + fi + + all_container_names=$(docker ps --all --format "{{.Names}}") + COMPREPLY=($(compgen -W "$all_container_names" "${COMP_WORDS[1]}")) +} + +complete -F _docker-clear-log docker-clear-log diff --git a/completion/git-df.bash b/completion/git-df.bash new file mode 100644 index 0000000..e98c660 --- /dev/null +++ b/completion/git-df.bash @@ -0,0 +1 @@ +complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git-df diff --git a/docker-clear-log b/docker-clear-log new file mode 100755 index 0000000..cb3df32 --- /dev/null +++ b/docker-clear-log @@ -0,0 +1,21 @@ +#!/bin/bash -e + +CONTAINER=$1 + +if [[ -z $CONTAINER ]]; then + echo "No container specified" + exit 1 +fi + +if [[ "$(docker ps -aq -f name=^/"$CONTAINER"$ 2> /dev/null)" == "" ]]; then + + CONTAINER="$(docker-compose ps "$CONTAINER" 2> /dev/null | awk 'END {print $1}')" + + if [[ -z $CONTAINER ]]; then + echo "Container \"$1\" does not exist, exiting." + exit 1 + fi +fi + +LOG=$(docker inspect -f '{{.LogPath}}' "$CONTAINER" 2> /dev/null) +truncate -s 0 "$LOG" diff --git a/docker-rm-all b/docker-rm-all new file mode 100755 index 0000000..0be065a --- /dev/null +++ b/docker-rm-all @@ -0,0 +1,3 @@ +#!/bin/bash + +docker ps -a | awk '{ if (NR>1) system("docker rm " $1) }' diff --git a/docker-rm-images b/docker-rm-images new file mode 100755 index 0000000..ae48038 --- /dev/null +++ b/docker-rm-images @@ -0,0 +1,3 @@ +#!/bin/bash + +docker images | awk '{ if (NR>1) system("docker image rm " $3) }' diff --git a/get-layout b/get-layout new file mode 100755 index 0000000..abac3f9 --- /dev/null +++ b/get-layout @@ -0,0 +1,13 @@ +#!/bin/bash + +layout=$(setxkbmap -print -verbose 7 | grep layout: | awk '{print $2}') +variant=$(setxkbmap -print -verbose 7 | grep variant: | awk '{print $2}') + +if [[ $variant == "" ]]; then + output="${layout}" +else + output="${layout}-${variant}" +fi + +echo $output + diff --git a/getvol b/getvol new file mode 100755 index 0000000..7b61006 --- /dev/null +++ b/getvol @@ -0,0 +1,3 @@ +#!/bin/sh + +pactl list sinks | grep Volume | awk 'NR==1{print $5}' diff --git a/laptopkb-disable b/laptopkb-disable new file mode 100755 index 0000000..cbbe38d --- /dev/null +++ b/laptopkb-disable @@ -0,0 +1,8 @@ +#!/bin/bash + +# Written by Eric Ma (https://www.ericzma.com) + +id=$(laptopkb-get-id) + +xinput float $id + diff --git a/laptopkb-enable b/laptopkb-enable new file mode 100755 index 0000000..86923b2 --- /dev/null +++ b/laptopkb-enable @@ -0,0 +1,8 @@ +#!/bin/bash + +# Written by Eric Ma (https://www.ericzma.com) + +id=$(laptopkb-get-id) + +xinput reattach $id 3 + diff --git a/laptopkb-get-id b/laptopkb-get-id new file mode 100755 index 0000000..3c0ad9a --- /dev/null +++ b/laptopkb-get-id @@ -0,0 +1,5 @@ +#!/bin/bash + +# Written by Eric Ma (https://www.ericzma.com) + +xinput list | grep 'AT Translated Set' | cut -f2 | cut -d'=' -f2 diff --git a/laptoptouch-disable b/laptoptouch-disable new file mode 100755 index 0000000..30b2de8 --- /dev/null +++ b/laptoptouch-disable @@ -0,0 +1,8 @@ +#!/bin/bash + +# Written by Eric Ma (https://www.ericzma.com) + +id=$(laptopkb-get-id) + +xinput float "$(laptoptouch-get-id)" + diff --git a/laptoptouch-get-id b/laptoptouch-get-id new file mode 100755 index 0000000..642a60c --- /dev/null +++ b/laptoptouch-get-id @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +xinput list | grep 'Touchpad' | cut -f2 | cut -d'=' -f2 diff --git a/lock_screen b/lock_screen new file mode 100755 index 0000000..2495f0f --- /dev/null +++ b/lock_screen @@ -0,0 +1,3 @@ +#!/bin/bash + +xscreensaver-command -lock diff --git a/mutetog b/mutetog new file mode 100755 index 0000000..649162c --- /dev/null +++ b/mutetog @@ -0,0 +1,5 @@ +#!/bin/sh + +pactl set-sink-mute @DEFAULT_SINK@ toggle + +kill -46 $(pidof dwmblocks) diff --git a/poweroff b/poweroff new file mode 100755 index 0000000..27985aa --- /dev/null +++ b/poweroff @@ -0,0 +1,7 @@ +#!/bin/bash + +ans=$(printf "no\nyes" | dmenu -p "Shutdown?") + +if [ "$ans" = "yes" ]; then + /bin/poweroff +fi diff --git a/reboot b/reboot new file mode 100755 index 0000000..f399bbd --- /dev/null +++ b/reboot @@ -0,0 +1,7 @@ +#!/bin/bash + +ans=$(printf "no\nyes" | dmenu -p "Reboot?") + +if [ "$ans" = "yes" ]; then + /usr/bin/reboot +fi diff --git a/toggle-language b/toggle-language new file mode 100755 index 0000000..00fb6b9 --- /dev/null +++ b/toggle-language @@ -0,0 +1,18 @@ +#!/bin/bash + +layout=$(setxkbmap -print -verbose 7 | grep layout: | awk '{print $2}') +variant=$(setxkbmap -print -verbose 7 | grep variant: | awk '{print $2}') + +dvorak='enabled' + +if [[ $layout == "us" ]]; then + if [[ $dvorak == "enabled" ]]; then + setxkbmap gr-dvk + else + setxkbmap gr + fi +else + setxkbmap us dvp +fi + +kill -45 "$(pidof dwmblocks)" diff --git a/va2-capture b/va2-capture new file mode 100755 index 0000000..c9db472 --- /dev/null +++ b/va2-capture @@ -0,0 +1,105 @@ +#!/bin/bash + +set -x + +monitor="HDMI1" +xrandr_out="$(xrandr)" +output="/tmp/vid.mkv" + +find_device_info() { + pactl list sources \ + | grep "Name: ${1}" -A3 +} + +parse_device_name() { + echo "${1}" \ + | grep Name \ + | awk '{print $2}' +} + +parse_channels() { + echo "${1}" \ + | grep 'Sample Specification' \ + | awk '{print $4}' \ + | sed 's/ch//' +} + +parse_rate() { + echo "${1}" \ + | grep 'Sample Specification' \ + | awk '{print $5}' \ + | sed 's/Hz//' +} + +find_monitor_info() { + dev="${2}" + echo "${1}" \ + | awk "BEGIN {found = \"false\"} + /^${dev}/ {found = \"true\"; print \$0; next} + /^[[:space:]]/ {if (found == \"true\") {print \$0} } + /^\w/ {if (found == \"true\") {exit 0}}" +} + +get_monitor_size() { + dev="${2}" + echo "${1}" \ + | awk "/^${dev}.*primary/ {print \$4; exit} + /^${dev}/ {print \$3; exit}" \ + | sed 's/^\([[:digit:]]*x[[:digit:]]*\).*/\1/' +} + +get_monitor_pos() { + dev="${2}" + echo "${1}" \ + | awk "/^${dev}.*primary/ {print \$4; exit} + /^${dev}/ {print \$3; exit}" \ + | sed 's/.*\([[:digit:]]+[[:digit:]]*\)/\1/' \ + | sed 's/+/,/' +} + +get_monitor_rate() { + echo "${1}" \ + | awk '/*/ {print $2}' \ + | sed 's/\([[:digit:]]\+\).*/\1/' +} + +get_screen_number() { + echo "${1}" \ + | awk '/Screen / {print $2; exit 0}' \ + | sed 's/://' +} + +get_minimum() { + echo "${*}" \ + sed 's/ /\n/g' \ + | awk "BEGIN {min = 1000000000} + {if (\$1 < min) {min = \$1}} + END {print min}" +} + +odev_info=$(find_device_info "alsa_output") +odev=$(parse_device_name "${odev_info}") +odev_c=$(parse_channels "${odev_info}") +odev_r=$(parse_rate "${odev_info}") + +idev_info=$(find_device_info "alsa_input") +idev=$(parse_device_name "${idev_info}") +idev_c=$(parse_channels "${idev_info}") +idev_r=$(parse_rate "${idev_info}") + +min_sound_r=$(get_minimum "${odev_r}" "${idev_r}") + +mon_info=$(find_monitor_info "${xrandr_out}" "${monitor}") +mon_s=$(get_monitor_size "${mon_info}" "${monitor}") +mon_p=$(get_monitor_pos "${mon_info}" "${monitor}") +mon_r=$(get_monitor_rate "${mon_info}") + +screen=$(get_screen_number "${xrandr_out}") + +ffmpeg -f pulse -ac "${odev_c}" -ar "${odev_r}" -i "${odev}" \ + -f pulse -ac "${idev_c}" -ar "${idev_r}" -i "${idev}" \ + -filter_complex amix=inputs=2 \ + -f x11grab -s "${mon_s}" -r "${mon_r}" -probesize 100M -i "${DISPLAY}.${screen}+${mon_p}" \ + -vcodec libx264 -preset veryfast -crf 18 \ + -acodec libmp3lame -ar "${min_sound_r}" \ + "${output}" diff --git a/voldown b/voldown new file mode 100755 index 0000000..b76ba07 --- /dev/null +++ b/voldown @@ -0,0 +1,5 @@ +#!/bin/sh + +pactl set-sink-volume @DEFAULT_SINK@ -5% + +kill -46 $(pidof dwmblocks) diff --git a/volinfo b/volinfo new file mode 100755 index 0000000..a190331 --- /dev/null +++ b/volinfo @@ -0,0 +1,9 @@ +#!/bin/sh + +muted="$(pactl list sinks | grep "Mute" | awk '{print $2}')" + +if [ "$muted" = 'no' ]; then + echo " $(/home/vtimofei/scripts/getvol)" +else + echo " $(/home/vtimofei/scripts/getvol)" +fi diff --git a/volup b/volup new file mode 100755 index 0000000..f77b05f --- /dev/null +++ b/volup @@ -0,0 +1,5 @@ +#!/bin/sh + +pactl set-sink-volume @DEFAULT_SINK@ +5% + +kill -46 $(pidof dwmblocks)