This commit is contained in:
sankalp committed 2023-04-24 15:41:27 +05:45
1 parent 0b17aa140b
commit dde4ef218a
136 files changed
+9796

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
get_state () {
state=$(bluetoothctl show | grep 'Powered' | awk '{print $2}')
if [[ $state == "yes" ]]; then
echo on
else
echo off
fi
}
turn_off () {
bluetoothctl power off 2>&1 > /dev/null
}
turn_on () {
bluetoothctl power on 2>&1 > /dev/null
}
toggle () {
state=$(get_state)
if [[ $state == "on" ]]; then
turn_off
else
turn_on
fi
}
if [[ $1 == "state" ]]; then
get_state
fi
if [[ $1 == "toggle" ]]; then
toggle
fi
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
# @requires: brightnessctl
percentage () {
local val=$(echo $1 | tr '%' ' ' | awk '{print $1}')
local icon1=$2
local icon2=$3
local icon3=$4
local icon4=$5
if [ "$val" -le 15 ]; then
echo $icon1
elif [ "$val" -le 30 ]; then
echo $icon2
elif [ "$val" -le 60 ]; then
echo $icon3
else
echo $icon4
fi
}
get_brightness () {
(( br = $(brightnessctl get) * 100 / $(brightnessctl max) ))
echo $br
}
get_percent () {
echo $(get_brightness)%
}
get_icon () {
local br=$(get_percent)
echo $(percentage "$br" "" "" "" "")
}
if [[ $1 == "br" ]]; then
get_brightness
fi
if [[ $1 == "percent" ]]; then
get_percent
fi
if [[ $1 == "icon" ]]; then
get_icon
fi
if [[ $1 == "set" ]]; then
light -S $2
fi
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}' | tr '.' ' ' | awk '{print $1}'
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
df --output=pcent / | tail -n 1 | sed 's/%//g' | awk '{print $1}'
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
if [ "$1" = "status" ]; then
state=$(amixer sget Capture | grep "\[on\]")
if [ -n "$state" ]; then
echo "no"
else
echo "yes"
fi
elif [ "$1" = "toggle" ]; then
state=$(amixer sget Capture | grep "\[on\]")
if [ -n "$state" ]; then
amixer sset Capture nocap
echo "no"
else
amixer sset Capture cap
echo "yes"
fi
elif [ "$1" = "set" ] && [ "$2" -gt 0 ] && [ "$2" -le 100 ]; then
volume="$2%"
amixer sset Capture "${volume}"
echo "Volume set to ${volume}"
elif [ "$1" = "get" ]; then
(( mic_vol = $(amixer sget Capture | grep -oE '[0-9]+%' | tr -d '%') * 100 / 100 ))
echo $mic_vol
elif [ "$1" = "percent" ] && [ "$2" -gt 0 ] && [ "$2" -le 100 ]; then
amixer sset Capture "${2}%"
echo "Volume set to ${2}%"
else
echo "Usage: $0 [status|toggle|set|get|percent]"
fi
+100
View File
@@ -0,0 +1,100 @@
#!/bin/bash
symbol() {
[ $(cat /sys/class/net/w*/operstate) = down ] && echo 睊 && exit
echo
}
name() {
iwgetid -r
}
cut () {
toshow="$1"
maxlen="$2"
sufix=""
if test $(echo $toshow | wc -c) -ge $maxlen ; then
sufix=" ..."
fi
echo "${toshow:0:$maxlen}$sufix"
}
[ "$1" = "icon" ] && symbol
if [[ $1 == "ssid" ]]; then
ssid=$(name)
if [[ "$ssid" == "" ]]; then
cut "Disconnected" 10
else
cut "$ssid" 10
fi
fi
if [[ $1 == "name" || $1 == "class" ]]; then
wifiname=$(name)
if [[ $wifiname == "" ]]; then
if [[ $1 == "name" ]]; then
echo "Disconnected"
elif [[ $1 == "class" ]]; then
echo "disconnected"
fi
else
if [[ $1 == "name" ]]; then
echo "Connected to $wifiname"
elif [[ $1 == "class" ]]; then
echo "connected"
fi
fi
fi
if [[ $1 == "status" ]]; then
name=$(name)
if [[ $name != "" ]]; then
echo "Connected"
else
echo "Disconnected"
fi
fi
if [[ $1 == "disconnect" ]]; then
wifiname=$(nmcli d | grep wifi | sed 's/^.*wifi.*connected//g' | xargs)
nmcli con down id "${wifiname}"
fi
if [[ $1 == "connect" ]]; then
nmcli con up ifname "$(/usr/bin/ls /sys/class/ieee80211/*/device/net/)"
fi
if [[ $1 == "toggle" ]]; then
name=$(name)
if [[ "$name" == "" ]]; then
nmcli radio wifi on
else
nmcli radio wifi off
fi
fi
radio_status () {
radio_status=$(nmcli radio wifi)
if [[ $radio_status == "enabled" ]]; then
echo "on"
else
echo "off"
fi
}
if [[ $1 == "radio-status" ]]; then
radio_status
fi
if [[ $1 == "toggle-radio" ]]; then
stat=$(radio_status)
if [[ $stat == "on" ]]; then
nmcli radio wifi off
else
nmcli radio wifi on
fi
fi
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
declare -a profiles_photos=("$HOME/.face.jpg" "$HOME/.face.png")
for pfp in ${profiles_photos[@]}; do
if test -f $pfp; then
echo $pfp
exit 0
fi
done
echo $HOME/.config/eww/images/pp.png
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
percentage () {
local val=$(echo $1 | tr '%' ' ' | awk '{print $1}')
local icon1=$2
local icon2=$3
local icon3=$4
local icon4=$5
if [ "$val" -le 15 ]; then
echo $icon1
elif [ "$val" -le 30 ]; then
echo $icon2
elif [ "$val" -le 60 ]; then
echo $icon3
else
echo $icon4
fi
}
get_ram () {
free -m | grep Mem | awk '{print ($3/$2)*100}' | tr '.' ' ' | awk '{print $1}'
}
get_percent () {
echo $(get_ram)%
}
get_class () {
local percent=$(get_percent)
echo $(percentage "$percent" "yellow" "magenta" "purple" "red")
}
if [[ $1 == "ram" ]]; then
get_ram
fi
if [[ $1 == "percent" ]]; then
get_percent
fi
if [[ $1 == "class" ]]; then
get_class
fi
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
cache_file=$HOME/.cache/eww/services/redshift_state
initial_hook () {
if [ ! -d $(dirname $cache_file) ]; then
mkdir -p $(dirname $cache_file)
fi
if [ ! -f $cache_file ]; then
echo off > $cache_file
fi
}
get_state () {
# check if redshift is running
cat $cache_file
}
restore () {
local state=$(get_state)
if [[ $state == "on" ]]; then
enable_redshift
else
disable_redshift
fi
}
disable_redshift () {
redshift -x 2>&1 > /dev/null
# saving state
echo off > $cache_file
}
enable_redshift () {
redshift -x 2>&1 > /dev/null
redshift -O 5000 2>&1 > /dev/null
# saving new state
echo on > $cache_file
}
toggle () {
local state=$(get_state)
if [[ $state == "on" ]]; then
disable_redshift
else
enable_redshift
fi
}
initial_hook
if [[ $1 == "state" ]]; then
get_state
fi
if [[ $1 == "enable" ]]; then
enable_redshift
fi
if [[ $1 == "disable" ]]; then
disable_redshift
fi
if [[ $1 == "toggle" ]]; then
toggle
fi
if [[ $1 == "restore" ]]; then
restore
fi
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# thanks to rxyhn
path () {
local temp_path=null
for i in /sys/class/hwmon/hwmon*/temp*_input;
do
temp_path="$(echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null ||
echo $(basename ${i%_*})) $(readlink -f $i)");"
label="$(echo $temp_path | awk '{print $2}')"
if [ "$label" = "Package" ];
then
echo ${temp_path} | awk '{print $5}' | tr -d ';\n'
exit;
fi
done
}
get () {
local path=$(path)
if [[ $path == "" ]]; then
path="/sys/class/thermal/thermal_zone0/temp"
fi
local max_temp=100
local temp=$(cat $path)
jq -n $(jq -n $temp/1000)/$max_temp*100
}
_ () {
${@}
exit 0
}
if [[ $1 == "get" ]]; then
_ get
fi
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
name () {
username=$(whoami)
echo ${username^}
}
name
+91
View File
@@ -0,0 +1,91 @@
#!/bin/bash
# @requires: amixer
SINK=$(amixer scontrols | grep -oP "'[^']*'" | sed "s/'//g" | head -n 1)
percentage () {
local val=$(echo $1 | tr '%' ' ' | awk '{print $1}')
local icon1=$2
local icon2=$3
local icon3=$4
local icon4=$5
if [ "$val" -le 15 ]; then
echo $icon1
elif [ "$val" -le 30 ]; then
echo $icon2
elif [ "$val" -le 60 ]; then
echo $icon3
else
echo $icon4
fi
}
is_muted () {
amixer get Master | grep -o "\[off\]" | head -n 1
}
get_percentage () {
local muted=$(is_muted)
if [[ $muted == '[off]' ]]; then
echo 0%
else
per=$(amixer get $SINK | grep -o '[0-9]*%' | head -n 1 | tr -d '%')
echo "${per}%"
fi
}
get_icon () {
local vol=$(get_percentage)
if [[ $vol == "0%" ]]; then
echo "婢"
else
echo $(percentage "$vol" "" "" "墳" "")
fi
}
get_class () {
local vol=$(get_percentage)
if [[ $vol == "0%" ]]; then
echo "red"
else
echo $(percentage "$vol" "red" "magenta" "yellow" "blue")
fi
}
get_vol () {
local percent=$(get_percentage)
echo $percent | tr -d '%'
}
if [[ $1 == "icon" ]]; then
get_icon
fi
if [[ $1 == "class" ]]; then
get_class
fi
if [[ $1 == "percentage" ]]; then
get_percentage
fi
if [[ $1 == "vol" ]]; then
get_vol
fi
if [[ $1 == "muted" ]]; then
is_muted
fi
if [[ $1 == "toggle-muted" ]]; then
amixer set Master toggle
fi
if [[ $1 == "set" ]]; then
val=$(echo $2 | tr '.' ' ' | awk '{print $1}')
if test $val -gt 100; then
val=100
fi
amixer set $SINK $val%
fi
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/env bash
get_ws_name () {
local entry=$1
echo ${entry#?}
}
get_class_name () {
local entry=$1
echo ${entry} | sed 's/[0-9].*//g'
}
get_shape_by_class () {
local class=$1
local sfocused=$2
local sinactive=$3
local soccupied=$4
local afocused=$5
local ainactive=$6
local aoccupied=$7
# check focused
for info in $afocused; do
if [[ "$info" == "$class" ]]; then
echo $sfocused
fi
done
# check inactive
for info in $ainactive; do
if [[ "$info" == "$class" ]]; then
echo $sinactive
fi
done
# check occupied
for info in $aoccupied; do
if [[ "$info" == "$class" ]]; then
echo $soccupied
fi
done
}
workspaces () {
local info=$(echo $1 | sed 's/:/ /g')
local workspaces="(box :class \"ws\" :spacing \"-1\" :orientation \"h\" :halign \"center\" :space-evenly \"false\""
# define shapes
local sfocused=""
local sinactive=""
local soccupied=""
# define shapes associations
local afocused="A I" # focused and focused without childs
local ainactive="i" # unoccupied / inactive
local aoccupied="a" # occupied
# create buttons
for entry in $info; do
local name=$(get_ws_name $entry)
local class=$(get_class_name $entry)
local shape=$(get_shape_by_class "$class" "$sfocused" "$sinactive" "$soccupied" "$afocused" "$ainactive" "$aoccupied")
workspaces="${workspaces}(button :onclick \"dkcmd ws ${name}\" :class \"$class btn\" \"${shape}\")"
done
workspaces="$workspaces)"
echo $workspaces
}
dkcmd status type=ws | while read -r line; do
workspaces "$line"
done