dotfiles

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

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

linted and made changes

Diffstat:
A.local/bin/carbsopen | 14++++++++++++++
M.local/bin/checksunset | 40++++++++++++++++++++--------------------
M.local/bin/checktoday | 9++-------
M.local/bin/dsh | 6++++--
M.local/bin/dwatch | 10+++-------
M.local/bin/editstdout | 2+-
M.local/bin/fetchthedocs | 6++++--
M.local/bin/irc | 8++++----
M.local/bin/lockme | 2+-
M.local/bin/nlr | 6+++---
M.local/bin/powercheck | 2+-
M.local/bin/shortcuts | 3+++
M.local/bin/suspendsys | 2+-
D.local/bin/todo | 13-------------
D.local/bin/todoadd | 26--------------------------
D.local/bin/todorm | 8--------
D.local/bin/yousure | 8--------
D.local/bin/yousurereb | 8--------
18 files changed, 61 insertions(+), 112 deletions(-)

diff --git a/.local/bin/carbsopen b/.local/bin/carbsopen @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +file="$(realpath "$1")" +filetype="$(file --mime-type "$1" | awk 'NF>1{print $NF}')" +echo "$filetype" + +case "$filetype" in + text/*) $EDITOR "$file" ;; + video/*) nohup mpv "$file" >/dev/null 2>&1 & ;; + image/*) nohup sxiv "$file" >/dev/null 2>&1 & ;; + application/pdf) nohup zathura "$file" >/dev/null 2>&1 & ;; + audio/*) mpv --no-audio-display "$file" ;; + *) printf "Unknown application\\n"; exit 1 ;; +esac diff --git a/.local/bin/checksunset b/.local/bin/checksunset @@ -1,34 +1,34 @@ #!/usr/bin/env sh -! [ -e $HOME/.config/sunsetrc ] && printf "LAT=\nLON=\n" > $HOME/.config/sunsetrc -. $HOME/.config/sunsetrc +# shellcheck disable=SC1001,SC2154 -error() {\ - echo "Error: $1" - exit 1 -} +! [ -e "$HOME/.config/sunsetrc" ] && printf "LAT=\nLON=\n" > "$HOME/.config/sunsetrc" +. "$HOME/.config/sunsetrc" + +error() { echo "Error: $1"; exit 1;} jq --version >/dev/null 2>&1 || error "You must install jq to continue (https://stedolan.github.io/jq/)" -[ -e $HOME/.sunset ] || touch $HOME/.sunset -. $HOME/.sunset -[ "$checkdate" = `date +%Y%m%d` ] && exit # Don't check anything if you have already checked today. +[ -e "$HOME/.sunset" ] || touch "$HOME/.sunset" +. "$HOME/.sunset" +[ "$checkdate" = "$(date +%Y%m%d)" ] && exit # Don't check anything if you have already checked today. ping sunrise-sunset.org -c 1 -W 5 >/dev/null || exit 1 -if [ -z $LAT ] || [ -z $LON ]; then - PUBLIC_IP=`curl -s https://ipinfo.io/ip` - LAT=$(curl -s https://ipvigilante.com/${PUBLIC_IP} | \ +if [ -z "$LAT" ] || [ -z "$LON" ]; then + PUBLIC_IP="$( curl -s https://ipinfo.io/ip )" + LAT=$(curl -s https://ipvigilante.com/"${PUBLIC_IP}" | \ jq '.data.latitude' | \ cut -c 2- | rev | cut -c 2- | rev ) - LON=$(curl -s https://ipvigilante.com/${PUBLIC_IP} | \ + LON=$(curl -s https://ipvigilante.com/"${PUBLIC_IP}" | \ jq '.data.longitude' | cut -c 2- | rev | cut -c 2- | rev) fi -MORNING=$(date --date="TZ=\"UTC\" $(curl -s https://api.sunrise-sunset.org/json\?lat\=$LAT\&lng\=$LON\&date\=today | jq .results.sunrise | cut -c 2- | awk '{print $1}')" +%H%M) -NIGHT=$(date -d "$(date --date="TZ=\"UTC\" $(curl -s https://api.sunrise-sunset.org/json\?lat\=$LAT\&lng\=$LON\&date\=today | jq .results.sunset | cut -c 2- | awk '{print $1}')" +%H:%M) today + 12 hours" +%H%M) +MORNING=$(date --date="TZ=\"UTC\" $(curl -s https://api.sunrise-sunset.org/json\?lat\="$LAT"\&lng\="$LON"\&date\=today | jq .results.sunrise | cut -c 2- | awk '{print $1}')" +%H%M) +NIGHT=$(date -d "$(date --date="TZ=\"UTC\" $(curl -s https://api.sunrise-sunset.org/json\?lat\="$LAT"\&lng\="$LON"\&date\=today | jq .results.sunset | cut -c 2- | awk '{print $1}')" +%H:%M) today + 12 hours" +%H%M) -printf "\ -# Checked at `date`\n\ -SUNRISE=$MORNING\n\ -SUNSET=$NIGHT\n\ -checkdate=`date +%Y%m%d`\n" > $HOME/.sunset +cat > "$HOME/.sunset" <<EOF +# Checked at $(date) +SUNRISE=$MORNING +SUNSET=$NIGHT +checkdate=$(date +%Y%m%d) +EOF diff --git a/.local/bin/checktoday b/.local/bin/checktoday @@ -1,10 +1,5 @@ #!/usr/bin/env sh COMM=$(calcurse --appointment) - -if [ "$COMM" = "" ] -then - exit -else - notify-send "Today" "$COMM" -fi +[ -z "$COMM" ] && exit 0 +notify-send "Today" "$COMM" diff --git a/.local/bin/dsh b/.local/bin/dsh @@ -1,8 +1,10 @@ #!/usr/bin/env bash -. $HOME/.config/dshrc +# shellcheck disable=2154 + +. "$HOME/.config/dshrc" chosen="$(for i in $list; do printf "$i\\n"; done | dmenu -p "Choose shortcut")" -echo $chosen +echo "$chosen" [ -z "$chosen" ] && exit ${comms[$chosen]} diff --git a/.local/bin/dwatch b/.local/bin/dwatch @@ -1,10 +1,6 @@ #!/usr/bin/env sh -VID=$(ls $HOME/.watchlater | dmenu -l 30 -p "What will you watch") -if [ "$VID" = "" ] -then - exit -else - mpv $HOME/.watchlater/"$VID" >/dev/null 2>&1 & +VID=$(find "$HOME/.watchlater" -type f -printf "%f\n" | dmenu -l 30 -p "What will you watch") +[ -z "$VID" ] && exit + mpv "$HOME/.watchlater/$VID" >/dev/null 2>&1 & notify-send -u low "MPV" "Now Watching:\n$VID" -fi diff --git a/.local/bin/editstdout b/.local/bin/editstdout @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. $HOME/.profile +. "$HOME/.profile" tmpfile=$(mktemp /tmp/st-edit.XXXXXX) trap 'rm "$tmpfile"' 0 1 15 cat > "$tmpfile" diff --git a/.local/bin/fetchthedocs b/.local/bin/fetchthedocs @@ -1,10 +1,12 @@ #!/usr/bin/env sh +# shellcheck disable=1001 + out() { printf "$1\\n"; } error() { out "==> ERROR: $@"; } >&2 die() { error "$@"; exit 1; } wget -V >/dev/null 2>&1 || die 'wget is not installed' out "Installing carbs documentation to $HOME/.local/share/carbs/carbs.pdf" -mkdir -p $HOME/.local/share/carbs || die 'Could not create directory for carbs documentation' -wget -O $HOME/.local/share/carbs/carbs.pdf https://gitlab.cemkeylan.com/cemkeylan/carbsdocs/-/jobs/artifacts/master/raw/carbs.pdf\?job\=build || die 'Could not download carbs.pdf' +mkdir -p "$HOME/.local/share/carbs" || die 'Could not create directory for carbs documentation' +wget -O "$HOME/.local/share/carbs/carbs.pdf" https://gitlab.cemkeylan.com/cemkeylan/carbsdocs/-/jobs/artifacts/master/raw/carbs.pdf\?job\=build || die 'Could not download carbs.pdf' diff --git a/.local/bin/irc b/.local/bin/irc @@ -3,9 +3,9 @@ DEFHOST="irc.oftc.net" DEFPORT="6667" -if ! [ -e $HOME/.sicrc ] +if ! [ -e "$HOME/.sicrc" ] then - touch $HOME/.sicrc + :> "$HOME/.sicrc" UHOST="$(printf "irc.oftc.net\n" | dmenu -i -p "Hello, what host do you want to connect? (default: irc.oftc.net):")" [ -n "$UHOST" ] && HOST="$UHOST" || HOST="$DEFHOST" UPORT="$(printf "6667\n" | dmenu -i -p PORT:)" @@ -13,9 +13,9 @@ then UNICK="$(printf "$USER\n" | dmenu -i -p NICK:)" [ -n "$UNICK" ] && NICK="$UNICK" || NICK="$USER" printf \ -"#\n# Sic configuration\\n\\nHOST=\"$HOST\"\nPORT=\"$PORT\"\nNICK=\"$NICK\"\n" > $HOME/.sicrc +"#\n# Sic configuration\\n\\nHOST=\"$HOST\"\nPORT=\"$PORT\"\nNICK=\"$NICK\"\n" > "$HOME/.sicrc" notify-send "Simple IRC Client" "The file has been written to $HOME/.sicrc\n" fi -. $HOME/.sicrc +. "$HOME/.sicrc" st -t IRC -e /bin/sh -c "sic -n ${NICK} -h ${HOST} -p ${PORT}" diff --git a/.local/bin/lockme b/.local/bin/lockme @@ -1,6 +1,6 @@ #!/usr/bin/env sh -REALNAME="$(getent passwd $USER | cut -d ':' -f 5)" +REALNAME="$(getent passwd "$USER" | cut -d ':' -f 5)" [ -z "$REALNAME" ] && REALNAME=$USER mpc pause & sxlock -u "$REALNAME" 2>/dev/null || sxlock -f "-misc-liberation sans-medium-r-normal-*-*-*-*-*-*-*-*-*" -u "$REALNAME" diff --git a/.local/bin/nlr b/.local/bin/nlr @@ -15,8 +15,8 @@ if [ -z "$1" ]; then ! [ -e "$HOME/.nlr" ] && exit 1 while read -r line; do notify-send "Next Logon Reminder" "$line" - done < $HOME/.nlr - rm $HOME/.nlr + done < "$HOME/.nlr" + rm "$HOME/.nlr" else - echo "$1" >> $HOME/.nlr + echo "$1" >> "$HOME/.nlr" fi diff --git a/.local/bin/powercheck b/.local/bin/powercheck @@ -1,6 +1,6 @@ #!/usr/bin/env sh while : do - ! [ $(cat /sys/class/power_supply/BAT?/status) = "Charging" ] && [ $(cat /sys/class/power_supply/BAT?/capacity) -lt 25 ] && notify-send -u critical "Battery Status" "Your battery is low, please connect to a charger" + ! [ "$(cat /sys/class/power_supply/BAT?/status)" = "Charging" ] && [ "$(cat /sys/class/power_supply/BAT?/capacity)" -lt 25 ] && notify-send -u critical "Battery Status" "Your battery is low, please connect to a charger" sleep 500 done diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts @@ -1,5 +1,8 @@ #!/usr/bin/env sh # Unactivated progs should go to /dev/null + +# shellcheck disable=SC2016 + shellshortcuts="$HOME/.config/shortcutrc" dmenushortcuts="$HOME/.config/dshrc" lfshortcuts="$HOME/.config/lfshortcuts" diff --git a/.local/bin/suspendsys b/.local/bin/suspendsys @@ -1,4 +1,4 @@ #!/usr/bin/env sh -command -V systemctl >/dev/null 2>&1 && systemctl suspend && exit 0 +systemctl --version >/dev/null 2>&1 && systemctl suspend && exit 0 sudo -A zzz diff --git a/.local/bin/todo b/.local/bin/todo @@ -1,13 +0,0 @@ -#!/usr/bin/env sh - -if ! [ "$(calcurse --version 2>/dev/null)" ] -then - if [ -s $HOME/todo.txt ] - then - echo "$(head -n 1 $HOME/todo.txt) " - else - echo "Nothing to do!" - fi -else - cat $HOME/.calcurse/todo | head -n 1 - | cut -c 5- -fi diff --git a/.local/bin/todoadd b/.local/bin/todoadd @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -# Add to todo.txt file - -# pacman -Q calcurse >/dev/null 2>&1 && echo "There is currently no way to add a todo entry to Calcurse" || echo $1 | tee -a $HOME/todo.txt - - -if [ -z "$(pacman -T calcurse)" ] -then - if [ -z $1 ] - then - printf "Add a todo item: " - read todo - printf "Set priority [0-9]: " - read pri - re='^[0-9]+$' - if ! [[ $pri =~ $re ]] ; then - echo "error: Not a number" >&2; exit 1 - fi - echo -e "[$pri] $todo" >> $HOME/.calcurse/todo - else - echo $1 | xargs -r echo [0] | tee -a $HOME/.calcurse/todo - fi -else - echo $1 | tee -a $HOME/todo.txt -fi diff --git a/.local/bin/todorm b/.local/bin/todorm @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -if [ -z $(pacman -T calcurse) ] -then - tail -n +2 $HOME/.calcurse/todo > $HOME/.calcurse/todo.tmp && mv $HOME/.calcurse/todo.tmp $HOME/.calcurse/todo -else - tail -n +2 $HOME/todo.txt > $HOME/todo.txt.tmp && mv $HOME/todo.txt.tmp $HOME/todo.txt -fi diff --git a/.local/bin/yousure b/.local/bin/yousure @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -if [ $(printf 'No\nYes' | dmenu -p 'Are you sure you want to shutdown?') = 'Yes' ] -then - systemctl poweroff -else - exit -fi diff --git a/.local/bin/yousurereb b/.local/bin/yousurereb @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -if [ $(printf 'No\nYes' | dmenu -p 'Are you sure you want to reboot?') = 'Yes' ] -then - reboot -else - exit -fi