Skip to content

Instantly share code, notes, and snippets.

@sheepwall
Last active December 27, 2019 20:45
Show Gist options
  • Save sheepwall/75a986a3a6ff8a5871f465f1e7a74285 to your computer and use it in GitHub Desktop.
Save sheepwall/75a986a3a6ff8a5871f465f1e7a74285 to your computer and use it in GitHub Desktop.
scriptfiles
.local/bin scriptfiles to provide interface and OS background functionalities.
#!/bin/sh
#
# dmenu: logout, shutdown or lock
#
option=$(\
echo -e "Cancel\nShutdown\nReboot" \
| dmenu -i -p "Leave?" \
| tr '[:upper:]' '[:lower:]' \
)
case $option in
cancel) exit 1 ;;
reboot) sudo reboot ;;
shutdown) sudo shutdown 0 ;;
*) exit 1 ;;
esac
#!/bin/sh
#
# theme.sh:
# theme <theme-name>
# Toggle comments in Xrecources to activate <theme-name> resources and
# deactivate other themes' resources.
#
case $1 in
base16-nord | base16-solarized) echo "Changing theme...";;
*) echo "Theme not found." && exit 1 ;;
esac
XRFILE=$HOME/.config/Xresources
awk -v theme=$1 -v xrfile=$XRFILE '{
if (NF == 0) {
in_a_theme = 0;
in_correct_theme = 0;
}
if (in_a_theme && in_correct_theme) {
# Remove comments:
if (index($0, "!") == 1)
$0 = substr($0, 2);
} else if (in_a_theme) {
# Deactivate all other themes:
if (index($0, "!") != 1)
$0 = "!" $0;
}
if (index($0, "!::theme")) {
in_a_theme = 1;
if (index($0, theme))
in_correct_theme = 1;
}
print $0 > xrfile;
}' \
$XRFILE
xrdb $XRFILE
#!/bin/sh
#
# wallpaper: [change and] set wallpaper
# wallpaper [<wallpaper-file>] [<wallpaper-folder>]
#
[ ! -z $WALLPAPERDIR ] && DIR=$WALLPAPERDIR
[ ! -z $2 ] && DIR=$2
[ -z $DIR ] && echo Error: no directory && exit 1
[ ! -z $1 ] && [ -f $1 ] && cp $1 $DIR/_current
[ -f $DIR/_current ] && xwallpaper --center $DIR/_current
#!/bin/sh
#
# Search the web!
# $1: phrase
# $2: [engine]=ddg
#
[ -z "$1" ] && exit 1 || phrase=$(echo $1 | sed 's/^\s*//g ; s/\s*$//g ; s/\s/\+/g')
[ -z "$2" ] && engine="ddg" || engine=$2
case $engine in
ddg) surf https://duckduckgo.com/?q=$phrase & ;;
g) surf https://google.com/search?q=$phrase & ;;
yt) surf https://youtube.com/results?search_query=$phrase & ;;
*) surf https://duckduckgo.com/?q=$phrase & ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment