dotfiles

Cem's Dotfiles
git clone git://git.ckyln.com/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 29ee9d9dd6f4b2ec4cde3a6ad505c6306c2dd3e2
parent b6ddea1db17af04835369acc1eb93fed4686f8d1
Author: Cem Keylan <cem@ckyln.com>
Date:   Sun, 17 Nov 2019 14:21:43 +0300

linted and simplified

Diffstat:
M.local/bin/nightmodecheck | 37+++++++++----------------------------
M.local/bin/nightmodetoggle | 51++++++++++++++++++++++-----------------------------
M.local/bin/wallset | 24+++++++++---------------
3 files changed, 40 insertions(+), 72 deletions(-)

diff --git a/.local/bin/nightmodecheck b/.local/bin/nightmodecheck @@ -1,30 +1,11 @@ #!/usr/bin/env sh -if [ -e $HOME/.night ] -then - if [ $(head -n +1 $HOME/.night) = "CLICK=1" ] - then - CLICK="Overriden" - else - CLICK="0" - fi - if [ $(tail -n -1 $HOME/.night) = "NIGHT=0" ] - then - if [ $CLICK = "0" ] - then - echo "0" - else - echo "0 $CLICK" - fi - elif [ $(tail -n -1 $HOME/.night) = "NIGHT=1" ] - then - if [ $CLICK = "0" ] - then - echo "1" - else - echo "1 $CLICK" - fi - fi -else - echo There is a problem -fi +die() { echo There is a problem; exit 1; } + +[ -e "$HOME/.night" ] || die +. "$HOME/.night" + +[ "$CLICK" = 0 ] && RETCLICK="" || RETCLICK="Overriden" +[ "$NIGHT" = 0 ] && RETNIGHT="0" || RETNIGHT="1" + +[ -z "$RETCLICK" ] && echo "$RETNIGHT" || echo "$RETNIGHT $RETCLICK" diff --git a/.local/bin/nightmodetoggle b/.local/bin/nightmodetoggle @@ -1,40 +1,33 @@ #!/usr/bin/env sh -if [ -e $HOME/.night ] +if [ -e "$HOME/.night" ] then + . "$HOME/.night" case $1 in "click") - NIGHT=$(tail -n -1 $HOME/.night) - if [ $NIGHT = 'NIGHT=1' ] + if [ "$NIGHT" = '1' ] then - NIGHT='NIGHT=0' + sed -i 's/NIGHT=1/NIGHT=0/g' "$HOME/.night" else - NIGHT='NIGHT=1' + sed -i 's/NIGHT=0/NIGHT=1/g' "$HOME/.night" fi - echo 'CLICK=1' > $HOME/.night - echo $NIGHT >> $HOME/.night + sed -i 's/CLICK=0/CLICK=1/g' "$HOME/.night" ;; "disable") - NIGHT=$(tail -n -1 $HOME/.night) - echo 'CLICK=0' > $HOME/.night - echo $NIGHT >> $HOME/.night - $HOME/.local/bin/nightmodetoggle cron + sed -i 's/CLICK=1/CLICK=0/g' "$HOME/.night" + "$HOME/.local/bin/nightmodetoggle" cron exit ;; "cron") - if [ $(head -n +1 $HOME/.night) = "CLICK=1" ] + [ "$CLICK" = "1" ] && exit + [ -e "$HOME/.sunset" ] && . "$HOME/.sunset" + [ -z "$SUNSET" ] && SUNSET=1959 + [ -z "$SUNRISE" ] && SUNRISE=0600 + if [ "$(date +%H%M)" -gt "$SUNSET" ] || [ "$(date +%H%M)" -lt "$SUNRISE" ] then - exit + sed -i 's/NIGHT=0/NIGHT=1/g' "$HOME/.night" else - [ -e $HOME/.sunset ] && . $HOME/.sunset - [ -z $SUNSET ] && SUNSET=1959 - [ -z $SUNRISE ] && SUNRISE=0600 - if [ `date +%H%M` -gt "$SUNSET" ] || [ `date +%H%M` -lt "$SUNRISE" ] - then - printf "CLICK=0\nNIGHT=1" > $HOME/.night - else - printf "CLICK=0\nNIGHT=0" > $HOME/.night - fi + sed -i 's/NIGHT=1/NIGHT=0/g' "$HOME/.night" fi ;; *) @@ -42,14 +35,14 @@ then exit ;; esac - if [ $(tail -n -1 $HOME/.night) = "NIGHT=1" ] - then - - feh --bg-fill --randomize $HOME/Pictures/Wallpapers/Night/* + . "$HOME/.night" + if [ "$NIGHT" = 1 ]; then + feh --bg-fill --randomize "$HOME/Pictures/Wallpapers/Night"/* else - feh --bg-fill --randomize $HOME/Pictures/Wallpapers/Morning/* + feh --bg-fill --randomize "$HOME/Pictures/Wallpapers/Morning"/* fi else - touch $HOME/.night - printf "CLICK=0\nNIGHT=0" > $HOME/.night + :> "$HOME/.night" + printf "CLICK=0\nNIGHT=0\\n" > "$HOME/.night" + "$HOME/.local/bin/nightmodetoggle" disable fi diff --git a/.local/bin/wallset b/.local/bin/wallset @@ -1,17 +1,11 @@ #!/usr/bin/env sh -# Dmenu Script to change wallpaper -if [ $(tail -n -1 $HOME/.night) = "NIGHT=1" ] -then - export nightmode="Night" -else - export nightmode="Morning" -fi -export selection=$(ls $HOME/Pictures/Wallpapers/$nightmode | grep -i .jpg | dmenu -l 10) -if [ "$selection" = "" ] -then - exit -else - feh --bg-fill $HOME/Pictures/Wallpapers/$nightmode/$selection - notify-send 'New wallpaper' 'Your wallpaper has been changed !' -fi +die() { printf "==> ERROR: $1\\n"; exit 1; } + +[ -e "$HOME/.night" ] || die "Could not find $HOME/.night" +. "$HOME/.night" +[ "$NIGHT" = "1" ] && nightmode="Night" || nightmode="Morning" +selection="$(find "$HOME/Pictures/Wallpapers/$nightmode" -maxdepth 1 -name '*.jpg' -type f -printf "%f\n" | dmenu -l 10)" +[ -z "$selection" ] && die "no selection was made" +feh --bg-fill "$HOME/Pictures/Wallpapers/$nightmode/$selection" +notify-send 'New wallpaper' 'Your wallpaper has been changed !'