dot

packages and services management
Log | Files | Refs | README

commit 2480b2d4d1fda9d6e3b89d0a5c58d2a682d6f65f
parent 7f6e89c47d4b9425eae7c2bb086f6258a1589b51
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 12 Feb 2018 19:38:49 +0100

[ref] cleanup: merge or remove scripts

Diffstat:
Dbin/blawk | 44--------------------------------------------
Dbin/f | 2--
Dbin/fun-dump | 17-----------------
Mbin/fun-saber | 55+++++++++++++++++++++----------------------------------
Mbin/git-all | 4++--
Dbin/git-count | 6------
Mbin/lines | 2+-
Mbin/msearch | 2+-
Mbin/status | 12++++--------
Mbin/suckless-patch-mail | 4++--
Abin/term | 16++++++++++++++++
Dbin/term-inv | 3---
Dbin/term-name | 3---
Mbin/twt | 40+++++++++++++++++++---------------------
Mbin/wifi | 6+++++-
15 files changed, 71 insertions(+), 145 deletions(-)

diff --git a/bin/blawk b/bin/blawk @@ -1,44 +0,0 @@ -#!/usr/bin/awk -f -# Draw an image using block characters and ImageMagick -# blawk [columns lines] file [imagemagick_arguments] - -BEGIN { - if (ARGC <= 3) { - convert = "convert "ARGV[1]" -compress none "ARGV[2] \ - " pbm:- | sed -e 's/ //g' -ne '3,$ p'"; - } else { - convert = "convert "ARGV[3]" -compress none "ARGV[4] \ - " -resize "ARGV[1] * 2"x"ARGV[2] * 4 \ - " pbm:- | sed -e 's/ //g' -ne '3,$ p'"; - } - - - # Character number in a binary pattern from top left to bottom right - chmap[0] = 0x0020; chmap[1] = 0x2598; - chmap[2] = 0x259d; chmap[3] = 0x2580; - chmap[4] = 0x2596; chmap[5] = 0x258c; - chmap[6] = 0x259e; chmap[7] = 0x259b; - chmap[8] = 0x2597; chmap[9] = 0x259a; - chmap[10] = 0x2590; chmap[11] = 0x259c; - chmap[12] = 0x2584; chmap[13] = 0x2599; - chmap[14] = 0x259f; chmap[15] = 0x2588; - - while ((convert | getline) > 0 ) { - - # Get lines by group of 2 - line[1] = $0; - # Skip three lines to keep the aspect ratio - convert | getline; convert | getline; convert | getline; - line[2] = $0; - - for (i = 1; 2 * i < length(line[1]); i++) { - printf("%c", chmap[ \ - 1 * substr(line[1], 2 * i , 1) \ - + 2 * substr(line[1], 2 * i + 1, 1) \ - + 4 * substr(line[2], 2 * i , 1) \ - + 8 * substr(line[2], 2 * i + 1, 1) \ - ]); - } - print "" - } -} diff --git a/bin/f b/bin/f @@ -1 +0,0 @@ -io-find- \ No newline at end of file diff --git a/bin/fun-dump b/bin/fun-dump @@ -1,17 +0,0 @@ -#!/bin/sh -hexdump -C /dev/urandom | awk ' - - /eb/ { - printf("\033[1;32m"); - } - - /da/ { - printf("\033[1;7m"); - } - - { - gsub(/31/, "\033[1;31m##\033[m"); - gsub(/41/, "\033[1;7;31m**\033[m"); - printf("%s\033[m\n", $0); - } -' diff --git a/bin/fun-saber b/bin/fun-saber @@ -29,11 +29,9 @@ CONTROLS exit 1 } - -# -# This clears the screen, print the handle set cursor position at the middle of +# clear the screen, print the handle set cursor position at the middle of # the blade and saves it -# + print_handle() { h1='._________,_' @@ -52,7 +50,6 @@ print_handle() printf '\033[%sC\033[2A\033[s' "$width" } - print_blade() { color="$1" length="$2" @@ -67,7 +64,6 @@ print_blade() printf '\033[%sD' "$i" } - wait_button() { printf ' ' @@ -78,7 +74,6 @@ wait_button() print_handle '-' } - blink_blade() { color="$1" length="$2" @@ -113,7 +108,6 @@ blink_blade() done } - close_saber() { length="$1" @@ -141,32 +135,25 @@ close_saber() exit 0 } +color="${1:-1}" length="${2:-50}" -main() -{ - color="${1:-1}" length="${2:-50}" - - case "$1" in - [1-7] | '' ) : ;; - * ) help ;; - esac - - case "$2" in - [0-9] | [0-9][0-9] | 1[0-9][0-9] | '' ) : ;; - * ) help ;; - esac - - # close the saber while script stops - trap 'close_saber "$length" 4' INT - - { - printf '\n\n\n\033[?25l' - print_handle '=' - wait_button 4 - print_blade "$color" "$length" - blink_blade "$color" "$length" - } 2>/dev/null -} +case "$1" in +[1-7] | '' ) : ;; +* ) help ;; +esac + +case "$2" in +[0-9] | [0-9][0-9] | 1[0-9][0-9] | '' ) : ;; +* ) help ;; +esac +# close the saber while script stops +trap 'close_saber "$length" 4' INT -main "$@" +{ + printf '\n\n\n\033[?25l' + print_handle '=' + wait_button 4 + print_blade "$color" "$length" + blink_blade "$color" "$length" +} 2>/dev/null diff --git a/bin/git-all b/bin/git-all @@ -3,12 +3,12 @@ command="${1}" shift -find "${HOME}" -name .git | while IFS='' read repo +find "${HOME}" -name .git | sort | while IFS='' read repo do printf '%-40s ' "${repo%/.git}" ( cd "${repo%/.git}" || exit - git-status + git status -s --branch [ "${command}" ] && "${command}" "${@}" ) done diff --git a/bin/git-count b/bin/git-count @@ -1,6 +0,0 @@ -#!/bin/sh -printf '%d\n' $(( - $(git diff | grep ^+ | wc -l) - - $(git diff | grep ^- | wc -l) -)) - diff --git a/bin/lines b/bin/lines @@ -1,4 +1,4 @@ #!/bin/sh find "${@:-.}" -name '*.[ch]' -exec wc -l {} ';' | -awk '{ print; total += $1 } END { print total }' + awk '{ print; total += $1 } END { print total }' diff --git a/bin/msearch b/bin/msearch @@ -1,3 +1,3 @@ #!/bin/sh -e -mdirs "${MAILDIR}" | mlist | mpick "${@}" | mseq -S | mscan +mdirs "${VAR}/mail" | mlist | mpick "${@}" | mseq -S | mscan diff --git a/bin/status b/bin/status @@ -4,8 +4,6 @@ printf ' ' uptime | sed 's/.*: *//' | tr -d ',\n' printf ' ' -# battery - case "$(uname)" in (Linux) cat /sys/class/power_supply/BAT*/capacity @@ -14,14 +12,12 @@ case "$(uname)" in sysctl hw.sensors | sed -nr 's/.*(acpibat.).*/\1/p' | sort -u | while IFS='' read -r bat do - bat="hw.sensors.${bat}" - max="$(sysctl -n "${bat}.watthour4" | tr -cd 0-9)" - cur="$(sysctl -n "${bat}.watthour3" | tr -cd 0-9)" + max="$(sysctl -n "hw.sensors.${bat}.watthour4" | tr -cd 0-9)" + cur="$(sysctl -n "hw.sensors.${bat}.watthour3" | tr -cd 0-9)" expr "${cur}" '*' 100 / "${max}" done ;; esac | xargs printf ' %s%%' +printf ' ' -printf ' ' - -date +'%Y/%m/%d %H:%M' +date +' %Y/%m/%d %H:%M' diff --git a/bin/suckless-patch-mail b/bin/suckless-patch-mail @@ -1,6 +1,6 @@ #!/bin/sh git send-email -1 \ - --subject-prefix="$(basename $(pwd))][PATCH" \ + --subject-prefix="$(basename "$PWD")][PATCH" \ --to hackers@suckless.org \ - --smtp-server=$(command -v msmtp) + --smtp-server="$(command -v msmtp)" diff --git a/bin/term b/bin/term @@ -0,0 +1,16 @@ +#!/bin/sh + +case "${1}" in +(inv) + printf '\033[?5h' + ;; +(norm) + printf '\033[?5l' + ;; +(name) + shift + printf '\033]0;%s\a' "$*" + ;; +(*) + echo 'usage: term norm | inv | name <name>' +esac diff --git a/bin/term-inv b/bin/term-inv @@ -1,3 +0,0 @@ -#!/bin/sh - -[ "${#}" = 0 ] && printf '\033[?5%s' h || printf '\033[?5%s' l diff --git a/bin/term-name b/bin/term-name @@ -1,3 +0,0 @@ -#!/bin/sh - -printf '\033]0;%s\a' "$*" diff --git a/bin/twt b/bin/twt @@ -2,9 +2,7 @@ # twtxt client in a single small POSIX shell script NICK='josuah' -FEED="${HOME}/srv/twtxt.txt" -CONF="${HOME}/.config/twt" -CACHE="${HOME}/.cache/twt" +TWT="${HOME}/srv/twtxt.txt" awk_line=' @@ -89,8 +87,8 @@ err() exit 1 } -mkdir -p "${CACHE}" -touch "${CONF}" +mkdir -p "${VAR}/twt" +touch "${ETC}/twt" case "${1}" in (tweet) @@ -103,52 +101,52 @@ case "${1}" in new=$(printf %s "${usr}" | sed 's/[&/\]/\\&/g') usr=$(printf %s "${usr}" | sed 's/./[&]/g') msg=$(printf %s "${msg}" | sed "s/@${usr}/@<${new} ${url}>/") - done < "${CONF}" + done < "${ETC}/twt" printf '%s\t%s\n' "$(date +'%Y-%m-%dT%T%z' | sed 's/..$/:&/')" "${msg}" \ - >> "${FEED}" + >> "${TWT}" ;; (view) [ "${#}" -ne 2 ] && exec "${0}" - [ -f "${CACHE}/${2}" ] || err "${2} feed not found, try update" + [ -f "${VAR}/twt/${2}" ] || err "${2} feed not found, try update" - awk "${awk_line}" "${CACHE}/${2}" | sort -r | awk "${awk_show}" | ${PAGER} + awk "${awk_line}" "${VAR}/twt/${2}" | sort -r | awk "${awk_show}" | ${PAGER} ;; (timeline) [ "${#}" -ne 1 ] && exec "${0}" - ls "${CACHE}"/* 2> /dev/null 1>&2 || err 'no feed found, try to update' + ls "${VAR}/twt"/* 2> /dev/null 1>&2 || err 'no feed found, try to update' - awk "${awk_line}" "${CACHE}"/* | sort -r | awk "${awk_show}" | ${PAGER} + awk "${awk_line}" "${VAR}/twt"/* | sort -r | awk "${awk_show}" | ${PAGER} ;; (update) while read -r usr url do - curl -m 10 -#L "${url}" > "${CACHE}/${usr}" || - rm "${CACHE}/${usr}" & - done < "${CONF}" + curl -m 10 -#L "${url}" > "${VAR}/twt/${usr}" || + rm "${VAR}/twt/${usr}" & + done < "${ETC}/twt" wait ;; (follow) [ "${#}" -ne 3 ] && exec "${0}" - sed 's/[[:space:]].*//' "${CONF}" | grep -Fqx "${2}" && + sed 's/[[:space:]].*//' "${ETC}/twt" | grep -Fqx "${2}" && err "already following ${2}" - printf '%s\t%s\n' "${2}" "${3}" >> "${CONF}" - sort -uo "${CONF}" "${CONF}" + printf '%s\t%s\n' "${2}" "${3}" >> "${ETC}/twt" + sort -uo "${ETC}/twt" "${ETC}/twt" ;; (unfollow) [ "${#}" -ne 2 ] && exec "${0}" - sed 's/[[:space:]].*//' "${CONF}" | grep -Fqx "${2}" || + sed 's/[[:space:]].*//' "${ETC}/twt" | grep -Fqx "${2}" || err "not following ${2}" - sed "/^$(printf %s "${2}" | sed 's/./[&]/g')[[:space:]]/ d" "${CONF}" | - sort -uo "${CONF}" + sed "/^$(printf %s "${2}" | sed 's/./[&]/g')[[:space:]]/ d" "${ETC}/twt" | + sort -uo "${ETC}/twt" ;; (following) [ "${#}" -ne 1 ] && exec "${0}" sed -r 's/[[:space:]]/ /; s/(.{12}[^ ]*) */\1 @ /' \ - "${CONF}" + "${ETC}/twt" ;; (*) printf 'usage: twt [tweet msg | view user | timeline | update\n' diff --git a/bin/wifi b/bin/wifi @@ -2,4 +2,8 @@ [ "${#}" -ne 2 ] && exec printf 'usage: wifi <nwid> <wpa_passphrase>\n' -doas ifconfig iwm0 nwid "${1}" wpa wpakey "0x${2}" +case "$(uname)" in +(*BSD) + doas ifconfig iwm0 nwid "${1}" wpa wpakey "0x${2}" + ;; +esac