Made scripts more readable by moving most logic to functions.
This commit is contained in:
parent
86e3a3a79c
commit
5c738fdc77
@ -1,9 +1,6 @@
|
|||||||
#!/bin/env bash
|
#!/bin/env bash
|
||||||
|
|
||||||
# a script to quickly open up one of my many configs
|
# a script to quickly open up one of my many configs
|
||||||
|
|
||||||
source $HOME/.config/dmenu/config
|
|
||||||
|
|
||||||
editor="$TERMINAL -e $EDITOR"
|
editor="$TERMINAL -e $EDITOR"
|
||||||
|
|
||||||
declare -a configs=(
|
declare -a configs=(
|
||||||
@ -29,11 +26,21 @@ declare -a configs=(
|
|||||||
"xinitrc - $HOME/.config/X11/xinitrc"
|
"xinitrc - $HOME/.config/X11/xinitrc"
|
||||||
)
|
)
|
||||||
|
|
||||||
choice=$(printf '%s\n' "${configs[@]}" | $DMENU -l 10 -p 'Edit config:')
|
load_config () {
|
||||||
|
source $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
[ -z "$choice" ] && exit
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
[ "$choice" = "Quit" ] && exit
|
choice=$(printf '%s\n' "${configs[@]}" | $DMENU -l 10 -p 'Edit config:')
|
||||||
|
|
||||||
cfg=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
[ -z "$choice" ] && exit
|
||||||
$editor "$cfg"
|
|
||||||
|
[ "$choice" = "Quit" ] && exit
|
||||||
|
|
||||||
|
cfg=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||||
|
$editor "$cfg"
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
51
dmenu-games
51
dmenu-games
@ -1,8 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# dmenu script to open up my games
|
# dmenu script to open up my games
|
||||||
|
load_config () {
|
||||||
. $HOME/.config/dmenu/config
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
get_category () {
|
get_category () {
|
||||||
category=$( game-run list | $DMENU -p "Choose game category:")
|
category=$( game-run list | $DMENU -p "Choose game category:")
|
||||||
@ -10,25 +11,39 @@ get_category () {
|
|||||||
[ -z "$category" ] && exit 0
|
[ -z "$category" ] && exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
get_category
|
menu () {
|
||||||
|
while [ -z "$game" ]
|
||||||
|
do
|
||||||
|
|
||||||
while [ -z "$game" ]
|
if [ -z "$1" ]; then
|
||||||
do
|
game=$(game-run list "$category" | sed '/-18+/d' | $DMENU -p "Choose game to run:")
|
||||||
|
elif [ "$1" = "-a" ]; then
|
||||||
|
game=$(game-run list "$category" | $DMENU -p "Choose game to run:")
|
||||||
|
else
|
||||||
|
printf '%s\n' "Option $1 doesn't exit!!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
[ -z "$game" ] && get_category
|
||||||
game=$(game-run list "$category" | sed '/-18+/d' | $DMENU -p "Choose game to run:")
|
done
|
||||||
elif [ "$1" = "-a" ]; then
|
}
|
||||||
game=$(game-run list "$category" | $DMENU -p "Choose game to run:")
|
|
||||||
|
launch_game () {
|
||||||
|
if game-run launch "$game"; then
|
||||||
|
quick-notify "Game run" "Launching $game"
|
||||||
else
|
else
|
||||||
printf '%s\n' "Option $1 doesn't exit!!"
|
quick-notify "Game run" "Failed to launch $game"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
[ -z "$game" ] && get_category
|
main () {
|
||||||
done
|
load_config
|
||||||
|
|
||||||
if game-run launch "$game"; then
|
get_category
|
||||||
quick-notify "Game run" "Launching $game"
|
|
||||||
else
|
menu
|
||||||
quick-notify "Game run" "Failed to launch $game"
|
|
||||||
fi
|
launch_game
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
22
dmenu-kill
22
dmenu-kill
@ -2,16 +2,24 @@
|
|||||||
|
|
||||||
# kill those pesky proceses
|
# kill those pesky proceses
|
||||||
|
|
||||||
. $HOME/.config/dmenu/config
|
load_config () {
|
||||||
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
pid=$(ps -u $USER -o pid,%mem,%cpu,comm,cmd | sort -b -k3 -r | $DMENU -l 15 -i -p "Choose procces to kill: " | awk '{print $1}')
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
[ -n "$pid" ] || exit
|
pid=$(ps -u $USER -o pid,%mem,%cpu,comm,cmd | sort -b -k3 -r | $DMENU -l 15 -i -p "Choose procces to kill: " | awk '{print $1}')
|
||||||
|
|
||||||
answer=$(printf "yes\\nno" | $DMENU -p "Are you sure?")
|
[ -n "$pid" ] || exit
|
||||||
|
|
||||||
[ $answer = "yes" ] || exit
|
answer=$(printf "yes\\nno" | $DMENU -p "Are you sure?")
|
||||||
|
|
||||||
kill -15 $pid 2>/dev/null
|
[ $answer = "yes" ] || exit
|
||||||
|
|
||||||
quick-notify "Killed Procces" "$pid"
|
kill -15 $pid 2>/dev/null
|
||||||
|
|
||||||
|
quick-notify "Killed Procces" "$pid"
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -3,12 +3,24 @@
|
|||||||
# Feed this script a link or it will get it from your clipboard and it will give dmenu
|
# Feed this script a link or it will get it from your clipboard and it will give dmenu
|
||||||
# with some choice of programs to open the link with.
|
# with some choice of programs to open the link with.
|
||||||
|
|
||||||
. $HOME/.config/dmenu/config
|
load_config () {
|
||||||
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
case "$(printf "mpv\\nbrowser\\ncopy url [X11]\\ncopy url [Wayland]\\nw3m" | $DMENU -p "Open link with what program?")" in
|
menu () {
|
||||||
mpv) "$VIDEO" "$@" ;;
|
case "$(printf "mpv\\nbrowser\\ncopy url [X11]\\ncopy url [Wayland]\\nw3m" | $DMENU -p "Open link with what program?")" in
|
||||||
browser) "$BROWSER" "$@" > /dev/null;;
|
mpv) "$VIDEO" "$@" ;;
|
||||||
"copy url [X11]") echo "$@" | xclip -selection clipboard ;;
|
browser) "$BROWSER" "$@" > /dev/null;;
|
||||||
"copy url [Wayland]") echo "$@" | wl-copy -n ;;
|
"copy url [X11]") echo "$@" | xclip -selection clipboard ;;
|
||||||
w3m) readable "$@" | w3m -T text/html ;;
|
"copy url [Wayland]") echo "$@" | wl-copy -n ;;
|
||||||
esac
|
w3m) readable "$@" | w3m -T text/html ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
menu $@
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -1,40 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/env bash
|
||||||
|
|
||||||
# script to run a menu prompt when having more than 2 players since
|
# script to run a menu prompt when having more than 2 players since
|
||||||
# playerctl is bad at managing more than one player at the same time
|
# playerctl is bad at managing more than one player at the same time
|
||||||
|
|
||||||
source $HOME/.config/dmenu/config
|
load_config () {
|
||||||
|
source $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
command="$@"
|
main () {
|
||||||
[ -z "$command" ] && exit
|
load_config
|
||||||
instances=$(playerctl -l | wc -l)
|
|
||||||
|
|
||||||
slock=$(ps -C slock | sed -n '1!p' | awk '{ print $4 }' | sed 's/slock/running/')
|
command="$@"
|
||||||
|
[ -z "$command" ] && exit
|
||||||
|
instances=$(playerctl -l | wc -l)
|
||||||
|
|
||||||
if [ "$instances" = "0" ]; then
|
if [ "$instances" = "0" ]; then
|
||||||
exit
|
|
||||||
elif [ "$instances" -lt "2" ]; then
|
|
||||||
playerctl $command
|
|
||||||
elif [ "$slock" = "running" ]; then
|
|
||||||
if [ "$command" = "play-pause" ]; then
|
|
||||||
if playerctl status -a | grep -i "Playing" > /dev/null; then
|
|
||||||
playerctl pause -a
|
|
||||||
else
|
|
||||||
playerctl -p mpd $command
|
|
||||||
fi
|
|
||||||
exit
|
exit
|
||||||
|
elif [ "$instances" -lt "2" ]; then
|
||||||
|
playerctl $command
|
||||||
|
else
|
||||||
|
choice=$(playerctl -l | $DMENU -p 'Manage:')
|
||||||
|
[ -z "$choice" ] && exit
|
||||||
|
playerctl -p $choice $command
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
players=$(paste <(playerctl -l) <(playerctl status -a) | grep -v -i mpd | awk '{print $1}')
|
main $@
|
||||||
if [ ! -z "$players" ]; then
|
|
||||||
for player in $players; do
|
|
||||||
playerctl -p $player pause
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
playerctl -p mpd $command
|
|
||||||
else
|
|
||||||
choice=$(playerctl -l | $DMENU -p 'Manage:')
|
|
||||||
[ -z "$choice" ] && exit
|
|
||||||
playerctl -p $choice $command
|
|
||||||
fi
|
|
||||||
|
@ -2,9 +2,21 @@
|
|||||||
|
|
||||||
# simple power menu script
|
# simple power menu script
|
||||||
|
|
||||||
. $HOME/.config/dmenu/config
|
load_config () {
|
||||||
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
case "$(printf "shutdown\\nreboot" | $DMENU -p "Choose your poison")" in
|
menu () {
|
||||||
"shutdown") poweroff ;;
|
case "$(printf "shutdown\\nreboot" | $DMENU -p "Choose your poison")" in
|
||||||
"reboot") reboot ;;
|
"shutdown") poweroff ;;
|
||||||
esac
|
"reboot") reboot ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
menu
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
14
dmenu-runner
14
dmenu-runner
@ -1,7 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
. $HOME/.config/dmenu/config
|
load_config () {
|
||||||
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
choice=$(dmenu_path | grep dmenu- | $DMENU -p "Choose script to run:")
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
$choice
|
choice=$(dmenu_path | grep dmenu- | $DMENU -p "Choose script to run:")
|
||||||
|
|
||||||
|
$choice
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# dmenu script for quickly setting ryzenadj profiles with my other script easily
|
# dmenu script for quickly setting ryzenadj profiles with my other script easily
|
||||||
|
load_config () {
|
||||||
. $HOME/.config/dmenu/config
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
get_category () {
|
get_category () {
|
||||||
category=$( sudo ryzenset list | $DMENU -p "Choose profile category:")
|
category=$( sudo ryzenset list | $DMENU -p "Choose profile category:")
|
||||||
@ -10,26 +11,43 @@ get_category () {
|
|||||||
[ -z "$category" ] && exit 0
|
[ -z "$category" ] && exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
get_category
|
get_current_profile () {
|
||||||
|
current_temp=$(sudo get-tctl-limit)
|
||||||
|
|
||||||
current_temp=$(sudo get-tctl-limit)
|
[ "$current_temp" = "60" ] && current_mode="normal mode"
|
||||||
|
[ "$current_temp" = "65" ] && current_mode="light gaming"
|
||||||
|
[ "$current_temp" = "70" ] && current_mode="heavy gaming"
|
||||||
|
[ "$current_temp" = "75" ] && current_mode="heavy programs"
|
||||||
|
[ "$current_temp" = "85" ] && current_mode="heavy gaming pro"
|
||||||
|
}
|
||||||
|
|
||||||
[ "$current_temp" = "60" ] && current_mode="normal mode"
|
menu () {
|
||||||
[ "$current_temp" = "65" ] && current_mode="light gaming"
|
while [ -z "$profile" ]
|
||||||
[ "$current_temp" = "70" ] && current_mode="heavy gaming"
|
do
|
||||||
[ "$current_temp" = "75" ] && current_mode="heavy programs"
|
profile=$(sudo ryzenset list $category | $DMENU -p "Current: $current_mode:")
|
||||||
[ "$current_temp" = "85" ] && current_mode="heavy gaming pro"
|
|
||||||
|
|
||||||
while [ -z "$profile" ]
|
[ -z "$profile" ] && get_category
|
||||||
do
|
done
|
||||||
|
}
|
||||||
|
|
||||||
profile=$(sudo ryzenset list $category | $DMENU -p "Current: $current_mode:")
|
launch_profile () {
|
||||||
|
if sudo ryzenset set "$profile"; then
|
||||||
|
quick-notify "Ryzenset" "Setting $profile"
|
||||||
|
else
|
||||||
|
quick-notify "Ryzenset" "Failed to set $game"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
[ -z "$profile" ] && get_category
|
main () {
|
||||||
done
|
load_config
|
||||||
|
|
||||||
if sudo ryzenset set "$profile"; then
|
get_category
|
||||||
quick-notify "Ryzenset" "Setting $profile"
|
|
||||||
else
|
get_current_profile
|
||||||
quick-notify "Ryzenset" "Failed to set $game"
|
|
||||||
fi
|
menu
|
||||||
|
|
||||||
|
launch_profile
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -2,13 +2,24 @@
|
|||||||
|
|
||||||
# It lets you choose the kind of screenshot to take, including
|
# It lets you choose the kind of screenshot to take, including
|
||||||
# copying the image or even highlighting an area to copy.
|
# copying the image or even highlighting an area to copy.
|
||||||
|
load_config () {
|
||||||
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
. $HOME/.config/dmenu/config
|
menu () {
|
||||||
|
case "$(printf "a selected area\\nfull screen" | $DMENU -l 6 -p "Screenshot which area?")" in
|
||||||
|
"a selected area") sleep 0.5; shotgun -g $(hacksaw) $dir/pic-selected-"$(date '+%y%m%d-%H%M-%S').png" ;;
|
||||||
|
"full screen") sleep 0.5; shotgun $dir/pic-full-"$(date '+%y%m%d-%H%M-%S').png" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
dir="$HOME/pics/screenshots"
|
main () {
|
||||||
[ ! -d "$dir" ] && mkdir $dir -p
|
dir="$HOME/pics/screenshots"
|
||||||
|
[ ! -d "$dir" ] && mkdir $dir -p
|
||||||
|
|
||||||
case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)" | $DMENU -l 6 -p "Screenshot which area?")" in
|
load_config
|
||||||
"a selected area") sleep 0.5; shotgun -g $(hacksaw) $dir/pic-selected-"$(date '+%y%m%d-%H%M-%S').png" ;;
|
|
||||||
"full screen") sleep 0.5; shotgun $dir/pic-full-"$(date '+%y%m%d-%H%M-%S').png" ;;
|
menu
|
||||||
esac
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
#!/bin/env bash
|
#!/bin/env bash
|
||||||
|
|
||||||
source $HOME/.config/dmenu/config
|
load_config () {
|
||||||
|
source $HOME/.config/dmenu/config
|
||||||
id=$(transmission-remote -l | $DMENU -l 10 | awk '{print $1}'| sed 's/*//')
|
}
|
||||||
|
|
||||||
[ -z "$id" ] && exit 0
|
|
||||||
|
|
||||||
move () {
|
move () {
|
||||||
declare -a paths=(
|
declare -a paths=(
|
||||||
@ -29,22 +27,34 @@ move () {
|
|||||||
else
|
else
|
||||||
quick-notify "Transmission" "Couldn't move $1 to $choice"
|
quick-notify "Transmission" "Couldn't move $1 to $choice"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$(printf "Start\\nStop\\nMove\\nRemove" | $DMENU -p "Torrent Action: ")" in
|
menu () {
|
||||||
Remove) transmission-remote -t $id -rad
|
case "$(printf "Start\\nStop\\nMove\\nRemove" | $DMENU -p "Torrent Action: ")" in
|
||||||
quick-notify "Transmission" "Removed $id"
|
Remove) transmission-remote -t $id -rad
|
||||||
;;
|
quick-notify "Transmission" "Removed $id"
|
||||||
Start) transmission-remote -t $id -s
|
;;
|
||||||
quick-notify "Transmission" "Started $id"
|
Start) transmission-remote -t $id -s
|
||||||
;;
|
quick-notify "Transmission" "Started $id"
|
||||||
Stop) transmission-remote -t $id -S
|
;;
|
||||||
quick-notify "Transmission" "Stoped $id"
|
Stop) transmission-remote -t $id -S
|
||||||
;;
|
quick-notify "Transmission" "Stoped $id"
|
||||||
Move) move $id
|
;;
|
||||||
;;
|
Move) move $id
|
||||||
*) quick-notify "Transmission" "No action chosen"
|
;;
|
||||||
;;
|
*) quick-notify "Transmission" "No action chosen"
|
||||||
esac
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
id=$(transmission-remote -l | $DMENU -l 10 | awk '{print $1}'| sed 's/*//')
|
||||||
|
|
||||||
|
[ -z "$id" ] && exit 0
|
||||||
|
|
||||||
|
menu
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
# a simple dmenu usb managment script
|
# a simple dmenu usb managment script
|
||||||
|
|
||||||
. $HOME/.config/dmenu/config
|
load_config () {
|
||||||
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
driveCount(){
|
driveCount(){
|
||||||
count="$(printf '%s\n' "$1" | wc -l)"
|
count="$(printf '%s\n' "$1" | wc -l)"
|
||||||
@ -30,7 +32,7 @@ mount(){
|
|||||||
|
|
||||||
unmount(){
|
unmount(){
|
||||||
mounted="$(lsblk -lp | awk '/run/ { print $1 " ("$4")" }')"
|
mounted="$(lsblk -lp | awk '/run/ { print $1 " ("$4")" }')"
|
||||||
|
|
||||||
if [ "$mounted" = "" ]; then
|
if [ "$mounted" = "" ]; then
|
||||||
quick-notify "Dmenu Usb Manager" "No drives to unmount"
|
quick-notify "Dmenu Usb Manager" "No drives to unmount"
|
||||||
exit
|
exit
|
||||||
@ -47,7 +49,17 @@ unmount(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
case $(printf "mount\\nunmount" | $DMENU -p "Chose your usb action") in
|
menu () {
|
||||||
"mount") mount ;;
|
case $(printf "mount\\nunmount" | $DMENU -p "Chose your usb action") in
|
||||||
"unmount") unmount ;;
|
"mount") mount ;;
|
||||||
esac
|
"unmount") unmount ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
menu
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
Loading…
Reference in New Issue
Block a user