From 1ff834e2b06761b083df9959d6c3d6bd2a94d2de Mon Sep 17 00:00:00 2001 From: Shubham Saini Date: Tue, 1 Dec 2020 20:21:04 +0000 Subject: mah thinkpad --- bin/.bin/bat_check | 14 ++++++++ bin/.bin/dotstow | 21 ++++++++++++ bin/.bin/fixmap | 2 ++ bin/.bin/gitit | 10 ++++++ bin/.bin/lay | 3 ++ bin/.bin/lay_both | 2 ++ bin/.bin/lay_edp | 2 ++ bin/.bin/lay_hdmi | 2 ++ bin/.bin/lemonconf | 74 ++++++++++++++++++++++++++++++++++++++++++ bin/.bin/light | 19 +++++++++++ bin/.bin/pcolor | 3 ++ bin/.bin/pkg | 22 +++++++++++++ bin/.bin/record | 10 ++++++ bin/.bin/shut | 11 +++++++ bin/.bin/statusbar | 45 +++++++++++++++++++++++++ bin/.bin/sysinfo | 20 ++++++++++++ bin/.bin/temp | 2 ++ bin/.bin/unblock | 8 +++++ bin/.bin/update-resolv-conf.sh | 71 ++++++++++++++++++++++++++++++++++++++++ bin/.bin/wpa | 16 +++++++++ 20 files changed, 357 insertions(+) create mode 100755 bin/.bin/bat_check create mode 100755 bin/.bin/dotstow create mode 100755 bin/.bin/fixmap create mode 100755 bin/.bin/gitit create mode 100755 bin/.bin/lay create mode 100755 bin/.bin/lay_both create mode 100755 bin/.bin/lay_edp create mode 100755 bin/.bin/lay_hdmi create mode 100755 bin/.bin/lemonconf create mode 100755 bin/.bin/light create mode 100755 bin/.bin/pcolor create mode 100755 bin/.bin/pkg create mode 100755 bin/.bin/record create mode 100755 bin/.bin/shut create mode 100755 bin/.bin/statusbar create mode 100755 bin/.bin/sysinfo create mode 100755 bin/.bin/temp create mode 100755 bin/.bin/unblock create mode 100755 bin/.bin/update-resolv-conf.sh create mode 100755 bin/.bin/wpa (limited to 'bin/.bin') diff --git a/bin/.bin/bat_check b/bin/.bin/bat_check new file mode 100755 index 0000000..547b976 --- /dev/null +++ b/bin/.bin/bat_check @@ -0,0 +1,14 @@ +#!/bin/bash +while true +do + battery_level=$(cat /sys/class/power_supply/BAT0/capacity) + state=$(cat /sys/class/power_supply/BAT0/status) + if [ $battery_level -ge 90 ] && [ $state == "Charging" ]; then + notify-send 'Pull the plug!' $battery_level% + elif [ $battery_level -le 30 -a $battery_level -ge 20 ] && [ $state == "Discharging" ]; then + notify-send 'Plug me!' $battery_level% + elif [ $battery_level -le 20 ] && [ $state == "Discharging" ]; then + notify-send -u critical 'Plug me NOW!' $battery_level% + fi + sleep 300 # 300 seconds or 5 minutes +done diff --git a/bin/.bin/dotstow b/bin/.bin/dotstow new file mode 100755 index 0000000..bcadc5e --- /dev/null +++ b/bin/.bin/dotstow @@ -0,0 +1,21 @@ +#!/bin/bash + +# This script will Stow all the dotfiles located in the ~/dotfiles folder. +# The -R flag is used to force a 'restow' which will remove any existing symlinks before attempting to Stow. + +echo "Stowing Dotfiles..."; + +cd ~/dotfiles +for file in ~/dotfiles/*; do + # Only run Stow on the directories in the dotfiles folder and not the individual files. + # Using 'basename' strips the filepath from the directory name. + if [ -d ${file} ]; then + stow -R $(basename $file) + echo "$(basename $file) stowed."; + fi +done + +# Return back to the your PWD from before you ran the script +cd ~- + +echo 'All stowed'; diff --git a/bin/.bin/fixmap b/bin/.bin/fixmap new file mode 100755 index 0000000..e937e7c --- /dev/null +++ b/bin/.bin/fixmap @@ -0,0 +1,2 @@ +#!/bin/bash +setxkbmap -layout us -option caps:ctrl_modifier diff --git a/bin/.bin/gitit b/bin/.bin/gitit new file mode 100755 index 0000000..5d576c2 --- /dev/null +++ b/bin/.bin/gitit @@ -0,0 +1,10 @@ +#!/bin/sh +set -e +printf "\033[0;32mDeploying updates to server...\033[0m\n" +git add . +msg="changes" +if [ -n "$*" ]; then + msg="$*" +fi +git commit -m "$msg" +git push origin master diff --git a/bin/.bin/lay b/bin/.bin/lay new file mode 100755 index 0000000..b891ab1 --- /dev/null +++ b/bin/.bin/lay @@ -0,0 +1,3 @@ +#!/bin/sh +~/bin/lay_hdmi +xrandr --output HDMI-1 --primary --mode 1366x768 --pos 0x0 --rotate normal --output eDP-1 --mode 1366x768 --pos 1366x0 --rotate normal diff --git a/bin/.bin/lay_both b/bin/.bin/lay_both new file mode 100755 index 0000000..245ff20 --- /dev/null +++ b/bin/.bin/lay_both @@ -0,0 +1,2 @@ +#!/bin/sh +xrandr --output eDP-1 --primary --mode 1366x768 --pos 0x0 --rotate normal --output HDMI-1 --mode 1366x768 --pos 0x0 --rotate normal diff --git a/bin/.bin/lay_edp b/bin/.bin/lay_edp new file mode 100755 index 0000000..e83d882 --- /dev/null +++ b/bin/.bin/lay_edp @@ -0,0 +1,2 @@ +#!/bin/sh +xrandr --output eDP-1 --primary --mode 1366x768 --pos 0x0 --rotate normal --output HDMI-1 --off diff --git a/bin/.bin/lay_hdmi b/bin/.bin/lay_hdmi new file mode 100755 index 0000000..9f84242 --- /dev/null +++ b/bin/.bin/lay_hdmi @@ -0,0 +1,2 @@ +#!/bin/sh +xrandr --output eDP-1 --off --output HDMI-1 --mode 1366x768 --pos 0x0 --rotate normal diff --git a/bin/.bin/lemonconf b/bin/.bin/lemonconf new file mode 100755 index 0000000..cb5e505 --- /dev/null +++ b/bin/.bin/lemonconf @@ -0,0 +1,74 @@ +#!/bin/bash +# Outputs a configuration for lemonbar + +vol(){ + vol=$(pulsemixer --get-volume | awk '{print $1}') + mute=$(pulsemixer --get-mute) + if [ "$mute" == 1 ]; then + echo -e "%{F#787878}vol%{F-} muted " + elif [ "$mute" == 0 ]; then + echo -e "%{F#787878}vol%{F-} $vol% " + fi +} + +bat() { + power=$(cat /sys/class/power_supply/BAT0/capacity) + status=$(cat /sys/class/power_supply/BAT0/status) + if [ "$status" == "Charging" ]; then + echo -e "%{F#787878}bat%{F-} +$power% " + elif [ "$status" == "Discharging" ]; then + echo -e "%{F#787878}bat%{F-} $power% " + fi +} + +dte() { + dte=$(date +"%a, %b %d") + echo -e "%{F#787878}date%{F-} $dte " +} + +tie() { + tme=$(date +"%I:%M %P") + echo -e "%{F#787878}time%{F-} $tme " +} + +groups() { + cur=`xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}'` + tot=`xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}'` + + for w in `seq 0 $((cur - 1))`; do line="${line}  "; done + line="${line}  " + for w in `seq $((cur + 2)) $tot`; do line="${line}  "; done + echo $line +} + +workspaces() { + all=$(bspc query -D) + occupied=$(bspc query -D -d .occupied) + current=$(bspc query -D -d .focused) + result="" + padding=" " + while IFS= read -r line; do + # Get the name of the current desktop + name="" + if [[ "$occupied" == *"$line"* ]]; + then + name="" + fi + + if [[ "$current" == *"$line"* ]]; + then + name="" + fi + + result="$result$padding" + result="$result$name" + result="$result$padding" + done <<< "$all" + echo -e "$result" +} + +while true; do + echo " $(vol) $(bat) $(tie) $(dte) %{F#787878}%{r}$(workspaces)%{F-} " + xdo above -t $(xdo id -n root) $(xdo id -n lemonbar) + sleep 3 +done diff --git a/bin/.bin/light b/bin/.bin/light new file mode 100755 index 0000000..bba7e82 --- /dev/null +++ b/bin/.bin/light @@ -0,0 +1,19 @@ +#!/bin/bash +# brightness wrapper + +case "$1" in + u*) + for f in /sys/class/backlight/*; do + echo $(($(<$f/brightness)+5*$(<$f/max_brightness)/100)) > $f/brightness; + done + ;; + d*) + for f in /sys/class/backlight/*; do + echo $(($(<$f/brightness)-5*$(<$f/max_brightness)/100)) > $f/brightness; + done + ;; + *) + echo "choose u or d" + ;; +esac + diff --git a/bin/.bin/pcolor b/bin/.bin/pcolor new file mode 100755 index 0000000..4cc28a0 --- /dev/null +++ b/bin/.bin/pcolor @@ -0,0 +1,3 @@ +#!/bin/bash +pcs() { for i in {0..7}; do echo -en "\e[${1}$((30+$i))m \u2588\u2588 \e[0m"; done; } +printf "\n%s\n%s\n\n" "$(pcs)" "$(pcs '1;')" diff --git a/bin/.bin/pkg b/bin/.bin/pkg new file mode 100755 index 0000000..5eea459 --- /dev/null +++ b/bin/.bin/pkg @@ -0,0 +1,22 @@ +#!/bin/sh + +case "$1" in + i*) + sudo xbps-install "$@" + ;; + d*) + sudo xbps-remove -R "$@" + ;; + q*) + sudo xbps-query "$@" + ;; + u*) + sudo xbps-install -Syu + ;; + o*) + sudo xbps-remove -Oo + ;; + *) + printf "i - install\nd - delete\nq - query\nu - update\no - remove obs" + ;; +esac diff --git a/bin/.bin/record b/bin/.bin/record new file mode 100755 index 0000000..5c6b499 --- /dev/null +++ b/bin/.bin/record @@ -0,0 +1,10 @@ +#!/bin/bash + +ffmpeg -f x11grab \ +-s 1980x1080 \ +-an -i :0.0 \ +-c:v libvpx \ +-b:v 5M \ +-crf 10 \ +-quality realtime \ +-y ~/record.mkv diff --git a/bin/.bin/shut b/bin/.bin/shut new file mode 100755 index 0000000..1fb1295 --- /dev/null +++ b/bin/.bin/shut @@ -0,0 +1,11 @@ +#!/bin/bash + +RET=$(echo -e "shutdown\nreboot\nsleep\nlock\ncancel" | dmenu -l 5 -p "Sayonara" -nb "#000000" -nf "#bfbfbf" -sb "#84a0c6" -sf "#000000" -fn "Hermit:size=10:antialias=true:autohint=true") + +case $RET in + shutdown) doas poweroff ;; + reboot) doas reboot ;; + sleep) xset s activate & doas zzz;; + lock) xset s activate ;; + *) ;; +esac diff --git a/bin/.bin/statusbar b/bin/.bin/statusbar new file mode 100755 index 0000000..c506244 --- /dev/null +++ b/bin/.bin/statusbar @@ -0,0 +1,45 @@ +#!/bin/bash + +# Color definitions. +export BLK="\e[30m" +export RED="\e[31m" +export GRN="\e[32m" +export YLW="\e[33m" +export BLU="\e[34m" +export PUR="\e[35m" +export CYN="\e[36m" +export RST="\e[0m" + +# Other formatting. +export BLD="\e[1m" +export DIM="\e[2m" +export ITA="\e[3m" +export UND="\e[4m" +export FLS="\e[5m" +export REV="\e[7m" +export INV="\e[8m" +export STR="\e[9m" + +vol(){ + vol=$(pulsemixer --get-volume | awk '{print $1}') + echo -e "vol $vol%" +} + +bat() { + power=$(cat /sys/class/power_supply/BAT0/capacity) + echo -e "bat $power%" +} + +dte() { + dte=$(date +"%A, %B %d") + echo -e "date $dte" +} + +tie() { + tme=$(date +"%I:%M %p") + echo -e "time $tme" +} +while :; do + echo "$(vol) $(bat) $(tie) $(dte)" + sleep 2 +done diff --git a/bin/.bin/sysinfo b/bin/.bin/sysinfo new file mode 100755 index 0000000..4f9f456 --- /dev/null +++ b/bin/.bin/sysinfo @@ -0,0 +1,20 @@ +#!/bin/bash +# +# System info + +wm="$(echo $XDG_CURRENT_DESKTOP)" +distro="$(cat /etc/*-release | grep PRETTY_NAME | cut -d '=' -f2 | tr -d '"')" +packages="$(xbps-query -l | wc -l)" +font="jetbrains mono" +colors="pencil" + +printf " \e[0m\n" +printf " \e[1;34m distro \e[0m$distro\n" +printf " \e[1;34m pkgs \e[0m$packages\n" +printf " \e[1;34m wm \e[0m$wm\n" +printf " \e[1;34m font \e[0m$font $fontsize\n" +printf " \e[1;34m colors \e[0m$colors\n" +printf " \e[0m\n" + +pcs() { for i in {0..7}; do echo -en "\e[${1}$((30+$i))m \u2588\u2588 \e[0m"; done; } +printf "\n%s\n%s\n\n" "$(pcs)" "$(pcs '1;')" diff --git a/bin/.bin/temp b/bin/.bin/temp new file mode 100755 index 0000000..fec8439 --- /dev/null +++ b/bin/.bin/temp @@ -0,0 +1,2 @@ +#!/bin/bash +paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/' diff --git a/bin/.bin/unblock b/bin/.bin/unblock new file mode 100755 index 0000000..257c4fb --- /dev/null +++ b/bin/.bin/unblock @@ -0,0 +1,8 @@ +#!/bin/sh +#whitelist escape +set -e +printf "\033[0;35mSetting wlo1 down....\033[0m\n" +sudo ip link set wlo1 down +printf "\033[0;36mChanging MAC address....\033[0m\n" +sudo macchanger --mac=FC:77:74:C7:71:71 wlo1 +printf "\033[0;32mEnjoy....\033[0m\n" diff --git a/bin/.bin/update-resolv-conf.sh b/bin/.bin/update-resolv-conf.sh new file mode 100755 index 0000000..16622a1 --- /dev/null +++ b/bin/.bin/update-resolv-conf.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# +# Parses DHCP options from openvpn to update resolv.conf +# To use set as 'up' and 'down' script in your openvpn *.conf: +# up /etc/openvpn/update-resolv-conf +# down /etc/openvpn/update-resolv-conf +# +# Used snippets of resolvconf script by Thomas Hood +# and Chris Hanson +# Licensed under the GNU GPL. See /usr/share/common-licenses/GPL. +# 07/2013 colin@daedrum.net Fixed intet name +# 05/2006 chlauber@bnc.ch +# +# Example envs set from openvpn: +# foreign_option_1='dhcp-option DNS 193.43.27.132' +# foreign_option_2='dhcp-option DNS 193.43.27.133' +# foreign_option_3='dhcp-option DOMAIN be.bnc.ch' +# foreign_option_4='dhcp-option DOMAIN-SEARCH bnc.local' + +## The 'type' builtins will look for file in $PATH variable, so we set the +## PATH below. You might need to directly set the path to 'resolvconf' +## manually if it still doesn't work, i.e. +## RESOLVCONF=/usr/sbin/resolvconf +export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin +RESOLVCONF=$(type -p resolvconf) + +case $script_type in + +up) + for optionname in ${!foreign_option_*} ; do + option="${!optionname}" + echo $option + part1=$(echo "$option" | cut -d " " -f 1) + if [ "$part1" == "dhcp-option" ] ; then + part2=$(echo "$option" | cut -d " " -f 2) + part3=$(echo "$option" | cut -d " " -f 3) + if [ "$part2" == "DNS" ] ; then + IF_DNS_NAMESERVERS="$IF_DNS_NAMESERVERS $part3" + fi + if [[ "$part2" == "DOMAIN" || "$part2" == "DOMAIN-SEARCH" ]] ; then + IF_DNS_SEARCH="$IF_DNS_SEARCH $part3" + fi + fi + done + R="" + if [ "$IF_DNS_SEARCH" ]; then + R="search " + for DS in $IF_DNS_SEARCH ; do + R="${R} $DS" + done + R="${R} +" + fi + + for NS in $IF_DNS_NAMESERVERS ; do + R="${R}nameserver $NS +" + done + #echo -n "$R" | $RESOLVCONF -x -p -a "${dev}" + echo -n "$R" | $RESOLVCONF -x -a "${dev}.inet" + ;; +down) + $RESOLVCONF -d "${dev}.inet" + ;; +esac + +# Workaround / jm@epiclabs.io +# force exit with no errors. Due to an apparent conflict with the Network Manager +# $RESOLVCONF sometimes exits with error code 6 even though it has performed the +# action correctly and OpenVPN shuts down. +exit 0 diff --git a/bin/.bin/wpa b/bin/.bin/wpa new file mode 100755 index 0000000..89f0141 --- /dev/null +++ b/bin/.bin/wpa @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +#https://github.com/icyphox/bin/blob/master/wpa +case "$1" in + r*) + sudo pkill wpa_supplicant + sudo wpa_supplicant -i wlp3s0 -B -c /etc/wpa_supplicant/wpa_supplicant.conf + ;; + n*) + sudo wpa_cli -i wlp3s0 select_network "$2" + ;; + l*) + sudo wpa_cli -i wlp3s0 list_networks + ;; + *) + sudo wpa_cli -i wlp3s0 "$*" +esac -- cgit v1.2.3