Created
November 27, 2023 14:23
-
-
Save kRHYME7/d159a3890bd8b066c7c56efaf581b0ba to your computer and use it in GitHub Desktop.
CLI for Hyprdots. WIp Not Merge yes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source ~/.config/hypr/scripts/globalcontrol.sh | |
ScrDir="$ConfDir/hypr/scripts" | |
ScriptDir="$CloneDir/Scripts" | |
cd $ScriptDir && echo "Hyprdots: $(git describe)" || exit 1 | |
func="${1}" | |
# Check for updates every 12 Hrs | |
[ ! -f "/tmp/hyprdots_update_check" ] || [[ $(find "/tmp/hyprdots_update_check" -mmin +720) ]] && \ | |
( echo "CloneDirectory: $CloneDir" && \ | |
git fetch > /dev/null 2>&1 && \ | |
( [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ] && echo -e "Updates available! \nRUN: \033[0;34mHyprdots update\033[0m" || echo -e "\033[0;32mHyprdots Up to date\033[0m" ) && \ | |
touch "/tmp/hyprdots_update_check" ) | |
params() { #TODO: Add conditionals here like 'case' 'getopts' 'ifelse' | |
func="${func// /}" | |
if awk "/^$func\(\) \{/,/}/" $0 | grep > /dev/null 'case'; then | |
awk "/^$func\(\) \{/,/}/" $0 | grep -E '^\s+\w+\)' | awk 'BEGIN { FS = "[()#?]" } { sub(/^[ \t]+/, "", $1); printf " %-15s %s\n","["$1"]", $4 }' | |
fi | |
} | |
man() { #? Show Manual | |
echo "Usage: Hyprdots [function] [parameters]" | |
echo "" | |
grep -E '^\w+ *\( *\)\s*\{ #\?' $0 | while read -r line; do | |
func=$(echo "$line" | awk 'BEGIN { FS = "[()#?]" } { print $1 }') | |
desc=$(echo "$line" | awk 'BEGIN { FS = "[()#?]" } { print $5 }') | |
printf " %-20s %s\n" "[$func]" "*$desc" | |
params "$func" | |
done | |
} | |
ConfigCtl() { | |
FILE="$1" | |
EDITOR="${EDITOR:-code}" # Use VS Code as the default editor | |
echo -e "[Editor]: $EDITOR (To change: \"export EDITOR=pref_editor\") \n[Monitor]: $FILE \nPress Any Key to end DAEMON..." | |
#kitty -o allow_remote_control=yes -o listen_on=unix:/tmp/mykitty $(which $EDITOR) "$FILE" > /dev/null 2>&1 & | |
kitty $(which $EDITOR) "$FILE" > /dev/null 2>&1 & | |
LAST_MD5SUM=$(md5sum "$FILE") | |
while true; do | |
CURRENT_MD5SUM=$(md5sum "$FILE") | |
if [ "$CURRENT_MD5SUM" != "$LAST_MD5SUM" ]; then | |
eval "$ACTION" | |
LAST_MD5SUM="$CURRENT_MD5SUM" | |
fi | |
read -t 2 -n 1 > /dev/null && exit 0 #? loop every 2 seconds | |
done | |
} | |
#! ================================================================ | |
#? Add functions below this section. | |
#? Be careful with spaces in your function definitions. | |
#? Example function: | |
#* |function example() { #? Example function. | |
#* | case $1 in | |
#* | # Cases go here... | |
#* | esac | |
#* |} | |
#! ================================================================ | |
restore() { #? Restore Hyprdots Configurations | |
./install.sh -r | |
} | |
update() { #? Pull Updates From Hyprdots Repository | |
git stash > /dev/null ; git pull ; git stash pop 2> /dev/null | |
rm -f "/tmp/hyprdots_update_check" | |
} | |
install() { #? Fresh install your config also installs apps. | |
./install.sh | |
} | |
theme() { #? Theme Related Actions | |
# Function for managing themes | |
case $1 in | |
set) #? Set Theme | |
$ScrDir/themeswitch.sh -s | |
;; | |
next) #? Next Theme | |
$ScrDir/themeswitch.sh -n | |
;; | |
prev) #? Previous Theme | |
$ScrDir/themeswitch.sh -p | |
;; | |
select) #? Theme Selector | |
$ScrDir/themeselect.sh | |
;; | |
patch) #? Patch A Theme from different repository. | |
shift | |
./themepatcher.sh "$@" | |
;; | |
*) | |
echo "$(params "${func}" )" | |
;; | |
esac | |
} | |
wallpaper() { #? Wallpaper related Actions | |
case $1 in | |
set) #? Set /Path/to/Wallpaper as Wallpaper | |
shift | |
if [ -z "$@" ]; then echo "Missing: /Path/to/Wallpaper" ; exit 1 ; fi | |
$ScrDir/swwwallpaper.sh -s "$@" | |
;; | |
next) #? Next Wallppaer | |
$ScrDir/swwwallpaper.sh -n | |
;; | |
prev) #? Previous Wallpaper | |
$ScrDir/sswwwallpaper.sh -p | |
;; | |
select) #? Wallpaper Selector | |
$ScrDir/swwwallselect.sh | |
;; | |
*) | |
echo "$(params "${func}" )" | |
;; | |
esac | |
} | |
sddm() { #? Sddm Things | |
# Function for managing SDDM settings | |
echo "Setting SDDM with parameters: $@" | |
case $1 in | |
set) #? Set active Wallpaper to Sddm Lockscreen | |
$ScrDir/sddmwall.sh | |
;; | |
*) | |
echo "$(params "${func}" )" | |
;; | |
esac | |
} | |
wallbash(){ #? Wallbash | |
case $1 in | |
toggle) #? Toggle Wall bash On/Off | |
$ScrDir/wallbashtoggle.sh | |
;; | |
*) | |
echo "$(params "${func}" )" | |
;; | |
esac | |
} | |
waybar() { #? Waybar related Things | |
case $1 in | |
config) #? Edit waybar Control File. | |
ACTION="notify-send -a \"Hyprdots\" \"Waybar Updated\" ; $ScrDir/wbarconfgen.sh ; killall waybar 2> /dev/null ; $(which waybar) > /dev/null 2>&1 & disown " | |
ConfigCtl "$HOME/.config/waybar/config.ctl" "$ACTION" | |
;; | |
*) | |
echo "$(params "${func}" )" | |
;; | |
esac | |
} | |
code() { | |
case $1 in | |
select) #? Selector for default Theme presets | |
if [[ ! -z "$(cat $HOME/.config/hypr/theme.ctl | grep "^1|" | cut -d'|' -f3)" ]]; then | |
dir=$(cat $ThemeCtl | grep "^1|" | cut -d'|' -f3 | cut -d'~' -f1 | tr '[:upper:]' '[:lower:]') | |
IFS=$'\n' read -d '' -ra theme < <(cat ~/.vscode/extensions/"${dir}"*/package.json | jq -r '.contributes.themes[] | .label') | |
select codet in "${theme[@]}" ; do echo "Vscode Theme: $codet" ; break ; done | |
sed -i "/^1|/s|~[^|]*|~${codet}|" $ThemeCtl | |
if [ "$(grep -c "workbench.colorTheme" $ConfDir/Code/User/settings.json)" -eq 1 ] ; then sed -i "/workbench.colorTheme/c\ \"workbench.colorTheme\": \"${codet}\"," $ConfDir/Code/User/settings.json | |
else sed -i "/^{/a\ \"workbench.colorTheme\": \"${codet}\"," $ConfDir/Code/User/settings.json | |
fi | |
fi | |
;; | |
*) | |
echo "$(params "${func}" )" | |
;; | |
esac | |
} | |
cache() { #? Run Caching | |
case $1 in | |
reload) #? Reload Caches if you have new wallpapers. | |
./create_cache.sh | |
;; | |
force) #? Force remove cache | |
./create_cache.sh -f | |
;; | |
add) #? Cache custom /path/to/wallpaper/* ( Broken) | |
if [[ -z $2 ]]; then | |
echo "Please provide a /path/to/wallpaper/*." | |
else | |
./create_cache.sh -c "$2" | |
fi | |
;; | |
*) | |
echo "$(params "${func}" )" | |
;; | |
esac | |
} | |
#! ================================================================ | |
#? Call the appropriate function based on the first argument | |
( [ -z "$1" ] && exit 1 ) || ( "$@" || ( grep -E '^\w+ *\( *\)\s*\{ #\?' $0 | awk 'BEGIN { FS = "[()#?]" } { printf " %-20s %s\n", $1, $5 }' ; exit 1 )) | |
#! ================================================================ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment