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,6 +26,13 @@ declare -a configs=(
|
|||||||
"xinitrc - $HOME/.config/X11/xinitrc"
|
"xinitrc - $HOME/.config/X11/xinitrc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
load_config () {
|
||||||
|
source $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
choice=$(printf '%s\n' "${configs[@]}" | $DMENU -l 10 -p 'Edit config:')
|
choice=$(printf '%s\n' "${configs[@]}" | $DMENU -l 10 -p 'Edit config:')
|
||||||
|
|
||||||
[ -z "$choice" ] && exit
|
[ -z "$choice" ] && exit
|
||||||
@ -37,3 +41,6 @@ choice=$(printf '%s\n' "${configs[@]}" | $DMENU -l 10 -p 'Edit config:')
|
|||||||
|
|
||||||
cfg=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
cfg=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||||
$editor "$cfg"
|
$editor "$cfg"
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
21
dmenu-games
21
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,8 +11,7 @@ get_category () {
|
|||||||
[ -z "$category" ] && exit 0
|
[ -z "$category" ] && exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
get_category
|
menu () {
|
||||||
|
|
||||||
while [ -z "$game" ]
|
while [ -z "$game" ]
|
||||||
do
|
do
|
||||||
|
|
||||||
@ -26,9 +26,24 @@ do
|
|||||||
|
|
||||||
[ -z "$game" ] && get_category
|
[ -z "$game" ] && get_category
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
launch_game () {
|
||||||
if game-run launch "$game"; then
|
if game-run launch "$game"; then
|
||||||
quick-notify "Game run" "Launching $game"
|
quick-notify "Game run" "Launching $game"
|
||||||
else
|
else
|
||||||
quick-notify "Game run" "Failed to launch $game"
|
quick-notify "Game run" "Failed to launch $game"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
get_category
|
||||||
|
|
||||||
|
menu
|
||||||
|
|
||||||
|
launch_game
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
# kill those pesky proceses
|
# kill those pesky proceses
|
||||||
|
|
||||||
|
load_config () {
|
||||||
. $HOME/.config/dmenu/config
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_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}')
|
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}')
|
||||||
|
|
||||||
@ -15,3 +20,6 @@ answer=$(printf "yes\\nno" | $DMENU -p "Are you sure?")
|
|||||||
kill -15 $pid 2>/dev/null
|
kill -15 $pid 2>/dev/null
|
||||||
|
|
||||||
quick-notify "Killed Procces" "$pid"
|
quick-notify "Killed Procces" "$pid"
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
# 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.
|
||||||
|
|
||||||
|
load_config () {
|
||||||
. $HOME/.config/dmenu/config
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
|
menu () {
|
||||||
case "$(printf "mpv\\nbrowser\\ncopy url [X11]\\ncopy url [Wayland]\\nw3m" | $DMENU -p "Open link with what program?")" in
|
case "$(printf "mpv\\nbrowser\\ncopy url [X11]\\ncopy url [Wayland]\\nw3m" | $DMENU -p "Open link with what program?")" in
|
||||||
mpv) "$VIDEO" "$@" ;;
|
mpv) "$VIDEO" "$@" ;;
|
||||||
browser) "$BROWSER" "$@" > /dev/null;;
|
browser) "$BROWSER" "$@" > /dev/null;;
|
||||||
@ -12,3 +15,12 @@ case "$(printf "mpv\\nbrowser\\ncopy url [X11]\\ncopy url [Wayland]\\nw3m" | $DM
|
|||||||
"copy url [Wayland]") echo "$@" | wl-copy -n ;;
|
"copy url [Wayland]") echo "$@" | wl-copy -n ;;
|
||||||
w3m) readable "$@" | w3m -T text/html ;;
|
w3m) readable "$@" | w3m -T text/html ;;
|
||||||
esac
|
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
|
||||||
|
|
||||||
|
load_config () {
|
||||||
source $HOME/.config/dmenu/config
|
source $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
command="$@"
|
command="$@"
|
||||||
[ -z "$command" ] && exit
|
[ -z "$command" ] && exit
|
||||||
instances=$(playerctl -l | wc -l)
|
instances=$(playerctl -l | wc -l)
|
||||||
|
|
||||||
slock=$(ps -C slock | sed -n '1!p' | awk '{ print $4 }' | sed 's/slock/running/')
|
|
||||||
|
|
||||||
if [ "$instances" = "0" ]; then
|
if [ "$instances" = "0" ]; then
|
||||||
exit
|
exit
|
||||||
elif [ "$instances" -lt "2" ]; then
|
elif [ "$instances" -lt "2" ]; then
|
||||||
playerctl $command
|
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
|
|
||||||
fi
|
|
||||||
|
|
||||||
players=$(paste <(playerctl -l) <(playerctl status -a) | grep -v -i mpd | awk '{print $1}')
|
|
||||||
if [ ! -z "$players" ]; then
|
|
||||||
for player in $players; do
|
|
||||||
playerctl -p $player pause
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
playerctl -p mpd $command
|
|
||||||
else
|
else
|
||||||
choice=$(playerctl -l | $DMENU -p 'Manage:')
|
choice=$(playerctl -l | $DMENU -p 'Manage:')
|
||||||
[ -z "$choice" ] && exit
|
[ -z "$choice" ] && exit
|
||||||
playerctl -p $choice $command
|
playerctl -p $choice $command
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -2,9 +2,21 @@
|
|||||||
|
|
||||||
# simple power menu script
|
# simple power menu script
|
||||||
|
|
||||||
|
load_config () {
|
||||||
. $HOME/.config/dmenu/config
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
|
menu () {
|
||||||
case "$(printf "shutdown\\nreboot" | $DMENU -p "Choose your poison")" in
|
case "$(printf "shutdown\\nreboot" | $DMENU -p "Choose your poison")" in
|
||||||
"shutdown") poweroff ;;
|
"shutdown") poweroff ;;
|
||||||
"reboot") reboot ;;
|
"reboot") reboot ;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
menu
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
load_config () {
|
||||||
. $HOME/.config/dmenu/config
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
choice=$(dmenu_path | grep dmenu- | $DMENU -p "Choose script to run:")
|
choice=$(dmenu_path | grep dmenu- | $DMENU -p "Choose script to run:")
|
||||||
|
|
||||||
$choice
|
$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,8 +11,7 @@ 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" = "60" ] && current_mode="normal mode"
|
||||||
@ -19,17 +19,35 @@ current_temp=$(sudo get-tctl-limit)
|
|||||||
[ "$current_temp" = "70" ] && current_mode="heavy gaming"
|
[ "$current_temp" = "70" ] && current_mode="heavy gaming"
|
||||||
[ "$current_temp" = "75" ] && current_mode="heavy programs"
|
[ "$current_temp" = "75" ] && current_mode="heavy programs"
|
||||||
[ "$current_temp" = "85" ] && current_mode="heavy gaming pro"
|
[ "$current_temp" = "85" ] && current_mode="heavy gaming pro"
|
||||||
|
}
|
||||||
|
|
||||||
|
menu () {
|
||||||
while [ -z "$profile" ]
|
while [ -z "$profile" ]
|
||||||
do
|
do
|
||||||
|
|
||||||
profile=$(sudo ryzenset list $category | $DMENU -p "Current: $current_mode:")
|
profile=$(sudo ryzenset list $category | $DMENU -p "Current: $current_mode:")
|
||||||
|
|
||||||
[ -z "$profile" ] && get_category
|
[ -z "$profile" ] && get_category
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
launch_profile () {
|
||||||
if sudo ryzenset set "$profile"; then
|
if sudo ryzenset set "$profile"; then
|
||||||
quick-notify "Ryzenset" "Setting $profile"
|
quick-notify "Ryzenset" "Setting $profile"
|
||||||
else
|
else
|
||||||
quick-notify "Ryzenset" "Failed to set $game"
|
quick-notify "Ryzenset" "Failed to set $game"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
get_category
|
||||||
|
|
||||||
|
get_current_profile
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
dir="$HOME/pics/screenshots"
|
menu () {
|
||||||
[ ! -d "$dir" ] && mkdir $dir -p
|
case "$(printf "a selected area\\nfull screen" | $DMENU -l 6 -p "Screenshot which area?")" in
|
||||||
|
|
||||||
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
|
|
||||||
"a selected area") sleep 0.5; shotgun -g $(hacksaw) $dir/pic-selected-"$(date '+%y%m%d-%H%M-%S').png" ;;
|
"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" ;;
|
"full screen") sleep 0.5; shotgun $dir/pic-full-"$(date '+%y%m%d-%H%M-%S').png" ;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
dir="$HOME/pics/screenshots"
|
||||||
|
[ ! -d "$dir" ] && mkdir $dir -p
|
||||||
|
|
||||||
|
load_config
|
||||||
|
|
||||||
|
menu
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
#!/bin/env bash
|
#!/bin/env bash
|
||||||
|
|
||||||
|
load_config () {
|
||||||
source $HOME/.config/dmenu/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,10 +27,9 @@ move () {
|
|||||||
else
|
else
|
||||||
quick-notify "Transmission" "Couldn't move $1 to $choice"
|
quick-notify "Transmission" "Couldn't move $1 to $choice"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menu () {
|
||||||
case "$(printf "Start\\nStop\\nMove\\nRemove" | $DMENU -p "Torrent Action: ")" in
|
case "$(printf "Start\\nStop\\nMove\\nRemove" | $DMENU -p "Torrent Action: ")" in
|
||||||
Remove) transmission-remote -t $id -rad
|
Remove) transmission-remote -t $id -rad
|
||||||
quick-notify "Transmission" "Removed $id"
|
quick-notify "Transmission" "Removed $id"
|
||||||
@ -48,3 +45,16 @@ case "$(printf "Start\\nStop\\nMove\\nRemove" | $DMENU -p "Torrent Action: ")" i
|
|||||||
*) 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
|
||||||
|
|
||||||
|
load_config () {
|
||||||
. $HOME/.config/dmenu/config
|
. $HOME/.config/dmenu/config
|
||||||
|
}
|
||||||
|
|
||||||
driveCount(){
|
driveCount(){
|
||||||
count="$(printf '%s\n' "$1" | wc -l)"
|
count="$(printf '%s\n' "$1" | wc -l)"
|
||||||
@ -47,7 +49,17 @@ unmount(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menu () {
|
||||||
case $(printf "mount\\nunmount" | $DMENU -p "Chose your usb action") in
|
case $(printf "mount\\nunmount" | $DMENU -p "Chose your usb action") in
|
||||||
"mount") mount ;;
|
"mount") mount ;;
|
||||||
"unmount") unmount ;;
|
"unmount") unmount ;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
load_config
|
||||||
|
|
||||||
|
menu
|
||||||
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
Loading…
Reference in New Issue
Block a user