From 294a49ed7cef4bfc2a92b7986b01780cbe03d171 Mon Sep 17 00:00:00 2001 From: Geoff Whatley Date: Thu, 23 May 2019 15:19:22 +1000 Subject: [PATCH] refactor(#39): rewrite zsh wttr.in wrappers in posix shell --- .zfuncs/forecast | 7 ------- .zfuncs/pomo | 14 +++++--------- .zfuncs/weather | 11 ----------- bin/blue | 2 +- bin/forecast | 0 bin/shellcheck | 5 ++--- bin/shfmt | 5 ++--- bin/tiz | 14 -------------- 8 files changed, 10 insertions(+), 48 deletions(-) delete mode 100644 .zfuncs/forecast delete mode 100644 .zfuncs/weather mode change 100644 => 100755 bin/forecast delete mode 100755 bin/tiz diff --git a/.zfuncs/forecast b/.zfuncs/forecast deleted file mode 100644 index f943160..0000000 --- a/.zfuncs/forecast +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env zsh - -local location - -location=${1:-Melbourne,Australia} - -curl -s "wttr.in/$location?q" diff --git a/.zfuncs/pomo b/.zfuncs/pomo index 4c084d1..d625c4b 100644 --- a/.zfuncs/pomo +++ b/.zfuncs/pomo @@ -1,6 +1,6 @@ -#!/usr/bin/env zsh +#!/usr/bin/zsh -set -euo pipefail +set -uo pipefail function usage() { cat << HEREDOC @@ -75,7 +75,7 @@ function pomo_help() { function pomo_timer() { local -i minutes=$1 - local message=${2:-get it done.} + local message=${2:-${message[${state[working]}}} # timer takes minutes, but we want to convert it to seconds local -i duration @@ -101,9 +101,6 @@ function pomo_start() { local -i short_break_duration local -i long_break_duration - # TODO: calculate and print total session time when complete - local -i session_start_time - local -i block_start_time local -i pomodoro_count local timer_state @@ -111,7 +108,6 @@ function pomo_start() { pomodoro_duration=25 short_break_duration=5 long_break_duration=15 - session_start_time=$(date +%s) pomodoro_count=0 timer_state=${state[working]} @@ -125,10 +121,10 @@ function pomo_start() { esac done + clear printf "%s\n\n" "pomo" while true; do - block_start_time=$(date +%s) pomo_notify ${title[$timer_state]} ${message[$timer_state]} ${icon[$timer_state]} printf "%s\n\n" "streak: $pomodoro_count" @@ -158,7 +154,7 @@ function pomo_start() { *) echo "impossible state" - exit 1 ;; + break ;; esac printf "\r\033[2A\033[K" diff --git a/.zfuncs/weather b/.zfuncs/weather deleted file mode 100644 index 064f1fa..0000000 --- a/.zfuncs/weather +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env zsh - -# weather -# alias weather="curl -s 'wttr.in/melbourne,australia?q0'" -# alias forecast="curl -s 'wttr.in/melbourne,australia?q'" - -local location - -location=${1:-Melbourne,Australia} - -curl -s "wttr.in/$location?q0" diff --git a/bin/blue b/bin/blue index 92c4233..275b589 100755 --- a/bin/blue +++ b/bin/blue @@ -1,6 +1,6 @@ #!/bin/sh -set -eu +set -e usage() { cat << HEREDOC diff --git a/bin/forecast b/bin/forecast old mode 100644 new mode 100755 diff --git a/bin/shellcheck b/bin/shellcheck index 678a8d9..1dde112 100755 --- a/bin/shellcheck +++ b/bin/shellcheck @@ -3,10 +3,9 @@ set -eu shellcheck() { - docker run -it --rm \ + docker run -it --rm --name="shellcheck" \ --volume "$PWD:/mnt" \ - --name shellcheck \ - koalaman/shellcheck "$@" + koalaman/shellcheck:latest "$@" } shellcheck "$@" diff --git a/bin/shfmt b/bin/shfmt index 300d6ed..9aed88c 100755 --- a/bin/shfmt +++ b/bin/shfmt @@ -3,10 +3,9 @@ set -eu shfmt() { - docker run -it --rm \ + docker run -it --rm --name="shfmt" \ --volume "$PWD:/work" \ - --name shfmt \ - tmknom/shfmt -i 2 "$@" + tmknom/shfmt:latest -i 2 "$@" } shfmt "$@" diff --git a/bin/tiz b/bin/tiz deleted file mode 100755 index 8561152..0000000 --- a/bin/tiz +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -eu - -user_id=$(id -u) -group_id=$(id -g) - -docker run -it --rm \ - -e PULSE_SERVER="unix:$XDG_RUNTIME_DIR/pulse/native" \ - --volume="$XDG_RUNTIME_DIR/pulse:$XDG_RUNTIME_DIR/pulse" \ - --volume="$HOME/.config/tizonia:/home/tizonia/.config/tizonia" \ - --volume "$HOME/.config/pulse/cookie:/home/tizonia/.config/pulse/cookie" \ - --name tizonia \ - tizonia/docker-tizonia "$@"