dot

packages and services management
Log | Files | Refs | README

commit d87fd0086b65d05c356288242ae863256b39c5b0
parent bbe197606d97ec0ceec151f71483aac82d222d36
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri,  2 Feb 2018 01:38:41 +0100

scripts syntax cleanup

Diffstat:
Mbin/80 | 14++++++--------
Mbin/agenda | 13+++++++------
Mbin/back | 3++-
Mbin/blih-openssl | 22++++++++++++----------
Mbin/clip | 2+-
Mbin/curl-0x0 | 1+
Mbin/curl-ix | 1+
Mbin/curl-rfc | 3++-
Mbin/curl-sprunge | 1+
Mbin/curl-w1r3 | 1+
Mbin/curl-wttr | 1+
Mbin/dns-used-tld | 33++++++++++++++++-----------------
Mbin/dvtm-status | 14+++++++-------
Dbin/edit | 3---
Mbin/etc | 26++++++++++++--------------
Mbin/fmt | 1+
Mbin/git-all | 7++++---
Mbin/io | 7+++----
Mbin/io-abduco | 8++++----
Mbin/io-find | 1+
Mbin/io-fs | 1-
Mbin/io-mail | 9++++++---
Mbin/io-man | 2+-
Mbin/io-netstat | 2+-
Mbin/io-ps | 5+++--
Mbin/io-sfeed | 2+-
Mbin/io-src | 2+-
Mbin/ipconv | 16++++++++--------
Mbin/mdoc | 2+-
Mbin/mfilter | 16++++++++--------
Mbin/monit | 41++++++++++++++++++++++++-----------------
Mbin/msearch | 2+-
Dbin/music | 27---------------------------
Mbin/mv-sane | 9+++++----
Mbin/piano | 3+--
Mbin/plot | 5++---
Mbin/status | 10+++++-----
Mbin/term-inv | 2+-
Mbin/tls | 18+++++++++---------
Mbin/tty-theme | 89+++++++++++++++++++++++++++----------------------------------------------------
Mbin/update-agenda | 4++--
Mdot/profile | 11++++-------
42 files changed, 197 insertions(+), 243 deletions(-)

diff --git a/bin/80 b/bin/80 @@ -1,14 +1,12 @@ #!/bin/sh -awk ' +awk ' BEGIN { ARGC = 1 } { - sub(" *\\" ARGV[2] "*$", " ", $0) - line = $0 + sub(" *\\" ARGV[2] "*$", " ", $0); + line = $0; for (i = 80 - length($0); i > 0; i--) - line = line ARGV[2] - print line -} - -' - "${1:--}" + line = line ARGV[2]; + print line; +}' - "${1:--}" diff --git a/bin/agenda b/bin/agenda @@ -1,9 +1,10 @@ #!/bin/sh # plain text agenda reading ical with its own simpler format -AGENDA="${AGENDA:-${HOME}/.config/agenda}" +AGENDA="${AGENDA:-${ETC:-${HOME}/.config}/agenda}" awk_date=' + function leap(yrs) { return (yrs % 4 == 0) && (yrs % 100 != 0) || (yrs % 400 == 0); @@ -176,8 +177,8 @@ END { name = FILENAME; sub(".*/", "", name); printf("[0|%s - %s - %s|/%s.txt|server|port]\n", - to_date("%d/%02d/%02d", minimum + 3600), - to_date("%d/%02d/%02d", maximum + 3600), name, FILENAME); + to_date("%d/%02d/%02d", minimum + 3600), + to_date("%d/%02d/%02d", maximum + 3600), name, FILENAME); }' @@ -193,8 +194,8 @@ case "${1}" in [ "${#}" -lt 2 ] || [ "${#}" -gt 3 ] && exec "${0}" awk -v SORT="${3:-BECLS}" "${awk_sort}" "${AGENDA}/${2}" | - awk -v OFF="$(date +%z | cut -c 1-3)" "${awk_view}" | - less + awk -v OFF="$(date +%z | cut -c 1-3)" "${awk_view}" | + less ;; (add) [ "${#}" -ne 4 ] && exec "${0}" @@ -214,7 +215,7 @@ case "${1}" in exec $EDITOR "${AGENDA}/$2" ;; (gopher) - find "${{AGENDA}#${PWD}/}" -type f ! -name '*.txt' \ + find "${AGENDA#${PWD}/}" -type f ! -name '*.txt' \ -exec awk "${awk_gopher}" {} \; | sort ;; (*) diff --git a/bin/back b/bin/back @@ -16,7 +16,8 @@ case "${1}" in -exec test "${log}" -nt {} ';' \ -exec grep -F {} "${log}" ';' -o \ -exec ${sum} {} + \ - ')' | tee "${BACK}/0/new" | + ')'| + tee "${BACK}/0/new" | while read -r hash path do [ -f "${BACK}/0/obj/${hash}.lz4" ] || diff --git a/bin/blih-openssl b/bin/blih-openssl @@ -1,22 +1,24 @@ #!/bin/sh # bocal lightweight interface for human client -usr=$BLIH -host=blih.epitech.eu +usr="${BLIH}" +host='blih.epitech.eu' printf 'password: ' 1>&2 stty -echo -IFS= read -r pwd +IFS='' read -r pwd stty echo -printf '\n' 1>&2 +printf '\n' -tok=$(printf %s "$pwd" | openssl dgst -sha512 | cut -d ' ' -f 2) -sig=$(printf %s "$usr" | openssl dgst -sha512 -hmac "$tok" | cut -d ' ' -f 2) -data='{"user": "'$usr'", "signature": "'$sig'"}' +tok="$(printf %s "${pwd}" | openssl dgst -sha512 | cut -d ' ' -f 2)" +sig="$(printf %s "${usr}" | openssl dgst -sha512 -hmac "${tok}" | + cut -d ' ' -f 2)" +data="{\"user\": \"${usr}\", \"signature\": \"${sig}\"}" method='GET' -request=$1 +request="${1}" -openssl s_client -connect "$host:443" -quiet << EOF 2>/dev/null | sed '1,/^.$/d' +openssl s_client -connect "${host}:443" -quiet 2> /dev/null \ + << EOF | sed '1,/^.$/d' $method //$request HTTP/1.1 Accept-Encoding: identity Content-Length: ${#data} @@ -25,7 +27,7 @@ Content-Type: application/json User-Agent: blih-1.7 Connection: close -$data +${data} EOF printf '\n' diff --git a/bin/clip b/bin/clip @@ -1,6 +1,6 @@ #!/bin/sh -e -CLIP=${CLIP:-${HOME}/.cache/clip} +CLIP="${CLIP:-${HOME}/.cache/clip}" touch "${CLIP}" chmod 600 "${CLIP}" diff --git a/bin/curl-0x0 b/bin/curl-0x0 @@ -1,2 +1,3 @@ #!/bin/sh + curl -F file=@- 0x0.st diff --git a/bin/curl-ix b/bin/curl-ix @@ -1,2 +1,3 @@ #!/bin/sh + curl -F f:1=@- ix.io diff --git a/bin/curl-rfc b/bin/curl-rfc @@ -1,2 +1,3 @@ #!/bin/sh -curl -L "http://www.ietf.org/rfc/rfc$1".txt | $PAGER + +curl -L "http://www.ietf.org/rfc/rfc${1}".txt | ${PAGER} diff --git a/bin/curl-sprunge b/bin/curl-sprunge @@ -1,2 +1,3 @@ #!/bin/sh + curl -F sprunge=@- sprunge.us diff --git a/bin/curl-w1r3 b/bin/curl-w1r3 @@ -1,2 +1,3 @@ #!/bin/sh + curl -F upload=@- w1r3.net diff --git a/bin/curl-wttr b/bin/curl-wttr @@ -1,2 +1,3 @@ #!/bin/sh + curl wttr.in diff --git a/bin/dns-used-tld b/bin/dns-used-tld @@ -1,40 +1,39 @@ #!/bin/sh # list all used TLD for a given SLD -: ${1:?Usage: ${0##*/} segond-level-domain} - +if [ "${#}" -ne 1 ] +then + echo 'usage: dns-used-tld <segond-level-domain>' + exit 0 +fi # get the list of the domains -[ -f /tmp/tlds-alpha-by-domain.txt ] || -wget -O- http://data.iana.org/TLD/tlds-alpha-by-domain.txt 2> /dev/null | -sed 1d > /tmp/tlds-alpha-by-domain.txt - +[ -f '/tmp/tlds-alpha-by-domain.txt' ] || +wget -O- 'http://data.iana.org/TLD/tlds-alpha-by-domain.txt' 2> /dev/null | +sed '1d' > '/tmp/tlds-alpha-by-domain.txt' # remove the false positive by checking a long random domain name # though, we cannot check for these domains now -if [ ! -f /tmp/tlds-false-positive.txt ] +if [ ! -f '/tmp/tlds-false-positive.txt' ] then touch /tmp/tlds-false-positive.txt - $0 "$( - tr -cd 0-9a-z < /dev/urandom | dd bs=32 count=1 2> /dev/null - )" > /tmp/tlds-false-positive.txt + "${0}" "$(tr -cd 0-9a-z < /dev/urandom | + dd bs=32 count=1 2> /dev/null)" > /tmp/tlds-false-positive.txt fi - -# check every domain, up to 5 at once - i=0 while read tld do - i=$((i + 1)) - dig -t NS "$1.$tld" | awk '/^[^;]/ && $3 == "IN" { + dig -t NS "${1}.${tld}" | awk '/^[^;]/ && $3 == "IN" { gsub("[^.]", "", $1) if (length($1) <= 1) exit 0 exit 1 - }' || echo "$tld" & - [ "$i" = 5 ] && wait + }' || printf '%s\n' "${tld}" & + + [ "${i}" = 5 ] && wait + i="$((i + 1))" done << EOF $(grep -vFf /tmp/tlds-false-positive.txt /tmp/tlds-alpha-by-domain.txt) EOF diff --git a/bin/dvtm-status b/bin/dvtm-status @@ -1,16 +1,16 @@ #!/bin/sh -FIFO="$HOME/.cache/run/dvtm-status.$$" +FIFO="${RUN}/dvtm-status.${$}" -[ -p "$FIFO" ] || mkfifo -m 600 "$FIFO" || exit 1 +[ -p "${FIFO}" ] || mkfifo -m 600 "${FIFO}" || exit 1 while true do - printf '%s\n' "$(status)" > "$FIFO" + printf '%s\n' "$(status)" > "${FIFO}" sleep 10 -done & PID=$! +done & PID="${!}" dvtm -s "$FIFO" "$@" 2> /dev/null -kill $PID -wait $PID 2> /dev/null -rm -f "$FIFO" +kill "${PID}" +wait "${PID}" 2> /dev/null +rm -f "${FIFO}" diff --git a/bin/edit b/bin/edit @@ -1,3 +0,0 @@ -#!/bin/sh - -EDITOR=vi VISUAL=vi exec less "$@" diff --git a/bin/etc b/bin/etc @@ -1,27 +1,25 @@ #!/bin/sh -e -ETC="$(cd "${0%/*}/.." && pwd)" +cd "${0%/*}/.." + +. dot/profile case "${1}" in (link) - cd "${ETC}" - find * -type d -exec mkdir -p "${HOME}/.config/{}" \; - find * ! -type d -exec ln -fs "${ETC}/{}" "${HOME}/.config/{}" \; + find * -type d -exec mkdir -p "${ETC}/{}" \; + find * ! -type d -exec ln -fs "${ETC}/{}" "${ETC}/{}" \; - cd "${ETC}/dot" - find * -type d -exec mkdir -p "${HOME}/.{}" \; - find * ! -type d -exec ln -fs "${ETC}/dot/{}" "${HOME}/.{}" \; + cd dot + find . -type d -exec mkdir -p "${HOME}/.{}" \; + find . ! -type d -exec ln -fs "${ETC}/dot/{}" "${HOME}/.{}" \; find -L "${HOME}" -maxdepth 2 -type l -exec rm {} + - find -L "${HOME}/.config" -type l -exec rm {} + ;; (mkdir) - mkdir -p "${HOME}/git" mkdir -p "${HOME}/tmp" - mkdir -p "${HOME}/.cache/log" - mkdir -p "${HOME}/.cache/run" - mkdir -p "${HOME}/.cache/mail/INBOX/cur" - mkdir -p "${HOME}/.cache/mail/INBOX/new" - mkdir -p "${HOME}/.cache/mail/INBOX/tmp" + mkdir -p "${VAR}/mail/cur" + mkdir -p "${VAR}/mail/new" + mkdir -p "${VAR}/mail/tmp" + mkdir -p "${HOME}/git" ;; (srv) git clone josuah@josuah.net:srv/git/srv.git "${HOME}/srv" diff --git a/bin/fmt b/bin/fmt @@ -1,2 +1,3 @@ #!/bin/sh + tr '\n' ' ' | fold -w 80 -s | sed 's/ *$//' diff --git a/bin/git-all b/bin/git-all @@ -1,13 +1,14 @@ #!/bin/sh -command="$1" + +command="${1}" shift -find "$HOME" -name .git | while IFS='' read repo +find "${HOME}" -name .git | while IFS='' read repo do printf '%-40s ' "${repo%/.git}" ( cd "${repo%/.git}" || exit git-status - [ "$command" ] && "$command" "$@" + [ "${command}" ] && "${command}" "${@}" ) done diff --git a/bin/io b/bin/io @@ -8,15 +8,14 @@ mkdir -p "${cache}" case "${PWD}" in ("${HOME}"/*) dir=$(printf %s "${PWD##${HOME}/}" | sed 's|/.*||') find "${HOME}/$dir" '(' -name .git -o -name CVS ')' -prune -o -print | - sort > "$cache/$dir" + sort > "${cache}/${dir}" esac exec xdg-open "$(find "${HOME}" -maxdepth 1 -mindepth 1 | sort | cut -c $((${#HOME} + 2))- | - xargs -I {} printf '%s/%s\n' "$cache" {} | + xargs -I {} printf '%s/%s\n' "${cache}" {} | xargs -I {} cat "${cache}" {} 2> /dev/null | cat - "${HOME}/etc/lib/uri" | iomenu -# | - cut -f 2- -)" + cut -f 2-)" diff --git a/bin/io-abduco b/bin/io-abduco @@ -1,12 +1,12 @@ #!/bin/sh -if [ $# -gt 0 ] +if [ "${#}" -gt 0 ] then - name=$1 + name="${1}" shift else name=$({ printf '#'; abduco; } | iomenu -# | cut -f4) fi -[ "$SSH_TTY" ] && e='^Z' || e='^\' -[ "$name" ] && ABDUCO=$name exec abduco -e "$e" -A "$name" "$@" +[ "${SSH_TTY}" ] && e='^Z' || e='^\' +[ "${name}" ] && ABDUCO="${name}" exec abduco -e "${e}" -A "${name}" "${@}" diff --git a/bin/io-find b/bin/io-find @@ -1,2 +1,3 @@ #!/bin/sh + find "${@:-.}" -name .git -prune -o -print | iomenu diff --git a/bin/io-fs b/bin/io-fs @@ -3,7 +3,6 @@ { printf '#spec .file .vfstype .mntops .freq .passno\n' | cat - /etc/fstab | column -ts ' ' - { printf '#device . .path . .type .mntops\n' mount diff --git a/bin/io-mail b/bin/io-mail @@ -2,8 +2,11 @@ export LC_COLLATE=C -mdirs "$HOME/.cache/mail" | sort | while IFS='' read -r dir -do printf '%s\t%s\n' "$(mlist -s "$dir" | wc -l)" "$dir" +mdirs "$HOME/.cache/mail" | sort | +while IFS='' read -r dir +do + printf '%s\t%s\n' "$(mlist -s "$dir" | wc -l)" "$dir" done | iomenu | cut -f 2 | mlist | mthread | msort -r -d | mseq -S | mscan -f '%6n %u %D %20f %t%2i%120S' | iomenu | -sed -r 's/^ *([0-9]*) .*/\1/'| xargs mless +sed -r 's/^ *([0-9]*) .*/\1/'| +xargs mless diff --git a/bin/io-man b/bin/io-man @@ -1,6 +1,6 @@ #!/bin/sh -export LC_COLLATE=C +export LC_COLLATE='C' man -k ' ' | sed -r ' s/ - / - / diff --git a/bin/io-netstat b/bin/io-netstat @@ -1,3 +1,3 @@ #!/bin/sh -netstat -a | sed 's/^[AP]/#&/' | iomenu -# +netstat -na | sed 's/^[AP]/#&/' | iomenu -# diff --git a/bin/io-ps b/bin/io-ps @@ -1,4 +1,5 @@ #!/bin/sh -{ ps -ax || ps; } | sed '1 s/^/#/' | iomenu -# | -sed -r 's/[^ ]* *([0-9]*).*/\1/' +{ + ps -ax || ps +} | sed '1 s/^/#/' | iomenu -# | sed -r 's/[^ ]* *([0-9]*).*/\1/' diff --git a/bin/io-sfeed b/bin/io-sfeed @@ -1,4 +1,4 @@ #!/bin/sh -exec xdg-open "$(find "$HOME/.sfeed/feeds" -type f -exec sfeed_plain {} + | +exec xdg-open "$(find "${HOME}/.sfeed/feeds" -type f -exec sfeed_plain {} + | iomenu -p sfeed | sed 's/.* //')" diff --git a/bin/io-src b/bin/io-src @@ -1,6 +1,6 @@ #!/bin/sh -less "$(find "$1" -name .git -prune -o -type f | sort | xargs -n 128 awk ' +less "$(find "${1}" -name .git -prune -o -type f | sort | xargs -n 128 awk ' FNR == 1 { printf("#%s\n", FILENAME); } { printf("%7s\t%s\n", FNR, $0); } ' | iomenu -# | cut -f 1)" diff --git a/bin/ipconv b/bin/ipconv @@ -1,25 +1,25 @@ #!/bin/sh -if [ -z "$1" ] || [ $# -ne 1 ] +if [ -z "${1}" ] || [ "${#}" -ne 1 ] then exit 1 elif [ -z "$(printf %s "$1" | tr -d 0-9)" ] then - int=$1 ip= + int="${1}" ip='' for i in 1 2 3 4 do - ip=.$((int & 255))$ip - int=$((int >> 8)); + ip=".$((int & 255))${ip}" + int="$((int >> 8))" done printf '%s\n' "${ip#?}" -elif [ -z "$(printf %s "$1" | tr -d 0-9.)" ] +elif [ -z "$(printf %s "${1}" | tr -d 0-9.)" ] then int=0 IFS=. - for byte in $1 + for byte in ${1} do - int=$(((int << 8) + byte)) + int="$(((int << 8) + byte))" done - printf '%s\n' "$int" + printf '%s\n' "${int}" else printf 'unknown address format\n' exit 1 diff --git a/bin/mdoc b/bin/mdoc @@ -1,6 +1,6 @@ #!/bin/sh -case $1 in +case "${1}" in (dd) date +'.Dd $Mdocdate: %B %d %Y$' ;; diff --git a/bin/mfilter b/bin/mfilter @@ -1,17 +1,17 @@ #!/bin/sh # read and filter mails using mblaze -minc "$MAILDIR/INBOX" > /dev/null +minc "${VAR}/mail/INBOX" > /dev/null while read -r dir header glob do - mkdir -p "$MAILDIR/$dir/cur" - mkdir -p "$MAILDIR/$dir/new" - mkdir -p "$MAILDIR/$dir/tmp" - printf '%-25s' "$dir" - mlist "$MAILDIR/INBOX" | mpick -t "$header ~~~ $glob" | - xargs -rI % mv % "$MAILDIR/$dir/new" -done << 'EOF' 2>&1 + mkdir -p "${VAR}/mail/${dir}/cur" + mkdir -p "${VAR}/mail/${dir}/new" + mkdir -p "${VAR}/mail/${dir}/tmp" + printf '%-25s' "${dir}" + mlist "${VAR}/mail/INBOX" | mpick -t "$header ~~~ $glob" | + xargs -rI % mv % "${VAR}/mail/${dir}/new" +done << 'EOF' actux.eu.org "List-Id" "*@actux.eu.org*" amazon.com "From" "*@amazon.*" amnesty.org "From" "*amnesty.*" diff --git a/bin/monit b/bin/monit @@ -8,9 +8,13 @@ # 3. free memory 7. total free storage # 4. cpu usage -DATA=$HOME/.cache/monit +DATA="${VAR}/monit" + +awk_record=' +#mem +#bi +#bo -awk_record='# -v mem -v bi -v bo BEGIN { "date +%s" | getline time; "hostname" | getline host; @@ -42,7 +46,9 @@ NR >= 4 { fflush(); }' -awk_plot='# -v STEP +awk_plot=' +#STEP offset between each entry + BEGIN { fields[2] = "time" fields[3] = "mem" @@ -79,30 +85,31 @@ END { }' case "$(uname)" in -(Linux ) mem=free bi=bi bo=bo ;; -(*BSD ) mem=fre bi='' bo='' ;; -(Solaris) mem=free bi='' bo='' ;; -(SunOS ) mem=free bi='' bo='' ;; +(Linux) mem='free' bi='bi' bo='bo' ;; +(*BSD) mem='fre' bi='' bo='' ;; +(Solaris) mem='free' bi='' bo='' ;; +(SunOS) mem='free' bi='' bo='' ;; esac -case $1 in +case "${1}" in (record) - [ $# -ne 2 ] && exec "$0" - vmstat "$2" | - awk -v mem="$mem" -v bi="$bi" -v bo="$bo" "$awk_record" >> "$DATA" + [ "${#}" -ne 2 ] && exec "${0}" + vmstat "${2}" | + awk -v mem="${mem}" -v bi="${bi}" -v bo="${bo}" "${awk_record}" \ + >> "${DATA}" ;; (step) - [ $# -ne 2 ] && exec "$0" - vmstat "$2" 2 | - awk -v mem="$mem" -v bi="$bi" -v bo="$bo" "$awk_record" >> "$DATA" + [ "${#}" -ne 2 ] && exec "${0}" + vmstat "${2}" 2 | + awk -v mem="${mem}" -v bi="${bi}" -v bo="${bo}" "${awk_record}" >> "${DATA}" ;; (plot) - [ $# -ne 2 ] && [ $# -ne 3 ] && exec "$0" + [ "${#}" -ne 2 ] && [ "${#}" -ne 3 ] && exec "${0}" tail -n 80 "$DATA" | - awk -v STEP="${2:?argument missing} step}" "$awk_plot" | + awk -v STEP="${2:?argument missing} step}" "${awk_plot}" | plot -h "${3:-10}" ;; (*) - printf 'usage: monit step | record | plot delay\n' + echo 'usage: monit step | record | plot delay' ;; esac diff --git a/bin/msearch b/bin/msearch @@ -1,3 +1,3 @@ #!/bin/sh -e -mdirs "${MAILDIR}" | mlist | mpick "$@" | mseq -S | mscan +mdirs "${MAILDIR}" | mlist | mpick "${@}" | mseq -S | mscan diff --git a/bin/music b/bin/music @@ -1,27 +0,0 @@ -#!/bin/sh -e - -PLAY=${PLAY:-$HOME/.cache/play} - -mkdir -p "$PLAY" - -[ -p "$PLAY/in" ] || mkfifo "$PLAY/in" - -case $1 in -(add) - test -r "$2" - printf '%s\n' "$2" >> "$PLAY/list" - ;; -(del) - awk "NR == $2 { next; } { print; }" "$PLAY/list" > "$PLAY/list.new" - mv "$PLAY/list.new" "$PLAY/list" - ;; -(next) - sed '1d' "$PLAY/list" > "$PLAY/list.new" - mv "$PLAY/list.new" "$PLAY/list" - ;; -(edit) - $EDITOR "$PLAY/list" - ;; -esac - -nl "$PLAY/list" diff --git a/bin/mv-sane b/bin/mv-sane @@ -3,8 +3,9 @@ find . -mindepth 1 | while IFS='' read -r path do - new=$(dirname "$path")/$(basename "$path" | - tr '\t #&;*?<>|"()[]{}\\-=+'\' _ | - sed -e 's/__*/_/g' -e 's/^_//' -e 's/_$//') - [ "$new" = "$path" ] || mv "$path" "$new" + new="$(dirname "$path")/$(basename "$path" | + tr '\t #&;*?<>|"()[]{}\\-=+'\' _ | + sed -e 's/__*/_/g' -e 's/^_//' -e 's/_$//')" + + [ "${new}" = "${path}" ] || mv "${path}" "${new}" done diff --git a/bin/piano b/bin/piano @@ -120,5 +120,4 @@ BEGIN { } system("stty -raw echo"); -} -' +}' diff --git a/bin/plot b/bin/plot @@ -4,7 +4,7 @@ awk ' BEGIN { if (ARGC != 3 || ARGV[1] != "-h") { - print "usage: plot -h [height]"; + print "usage: plot -h <height>"; exit(1); } height = ARGV[2] + ARGV[2] % 2; @@ -39,5 +39,4 @@ BEGIN { printf("%s", skip[x] ? "x" : "-"); print("+ " x_max); print("\n"); -} -' "$@" +}' "${@}" diff --git a/bin/status b/bin/status @@ -6,7 +6,7 @@ printf ' ' # battery -case $(uname) in +case "$(uname)" in (Linux) cat /sys/class/power_supply/BAT*/capacity ;; @@ -14,10 +14,10 @@ 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) - expr "$cur" '*' 100 / "$max" + bat="hw.sensors.${bat}" + max="$(sysctl -n "${bat}.watthour4" | tr -cd 0-9)" + cur="$(sysctl -n "${bat}.watthour3" | tr -cd 0-9)" + expr "${cur}" '*' 100 / "${max}" done ;; esac | xargs printf ' %s%%' diff --git a/bin/term-inv b/bin/term-inv @@ -1,3 +1,3 @@ #!/bin/sh -[ $# = 0 ] && printf '\033[?5%s' h || printf '\033[?5%s' l +[ "${#}" = 0 ] && printf '\033[?5%s' h || printf '\033[?5%s' l diff --git a/bin/tls b/bin/tls @@ -1,18 +1,18 @@ #!/bin/sh -case $1 in +case "${1}" in (update) - [ $# -eq 2 ] || exec "$0" + [ "${#}" -eq 2 ] || exec "${0}" set -ex - mkdir -p "$(dirname "$2")" + mkdir -p "$(dirname "${2}")" openssl req -x509 -newkey rsa:4096 -days 365 \ - -keyout "$2.key" -out "$2.pem" - chmod 400 "$2.key" - chmod 444 "$2.pem" - openssl dhparam -out "$2.dhp" 4096 - chmod 444 "$2.dhparams.pem" + -keyout "${2}.key" -out "${2}.pem" + chmod 400 "${2}.key" + chmod 444 "${2}.pem" + openssl dhparam -out "${2}.dhp" 4096 + chmod 444 "${2}.dhparams.pem" ;; (*) - printf 'usage: tls [update path]\n' + echo 'usage: tls [update path]' ;; esac diff --git a/bin/tty-theme b/bin/tty-theme @@ -1,7 +1,6 @@ #!/bin/sh # set the theme for the tty from a simple file format - # normal bold # 0 8 black # 1 9 red @@ -12,7 +11,35 @@ # 6 E cyan # 7 F white -THEMES=' +show='0' i='0' + +printf '\033[H\033[J' + +while read -r color hex +do + if [ "${hex}" ] + then + printf '\033]P%s%s' "${color}" "${hex}" + show='1' + elif [ "${color}" ] + then + name="${color}" + elif [ "${show}" -eq 1 ] + then + printf '\033[K%3s %-20s' "${i}" "${name}" + + for color in 0 1 2 3 4 5 6 7 + do + printf ' \033[3%sm___\033[1m___\033[m' "${color}" + done + printf '\n\033[K\n' + + show=0 + i="$((i + 1))" + fi + + [ "${1}" ] && [ "${i}" -ge "${1}" ] && return 0 +done << EOF lolidaisuki @@ -312,62 +339,6 @@ C 337799 D 888ba5 E 66ffee F eeffff -' - - -# 1: chosen theme number - -theme() -{ - show=0 i=0 - - printf '\033[H\033[J' - - while read -r color hex - do - if [ "$hex" ] - then - printf '\033]P%s%s' "$color" "$hex" - show=1 - elif [ "$color" ] - then - name="$color" - elif [ "$show" -eq 1 ] - then - i=$((i + 1)) - - printf '\033[K%3s %-20s' "$i" "$name" - for c in 0 1 2 3 4 5 6 7 - do - printf ' \033[3%sm___\033[1m___\033[m' "$c" - done - printf '\n\033[K\n' - - show=0 - fi - - [ "$1" ] && [ "$i" -ge "$1" ] && return 0 - done << EOF -$THEMES EOF -} - - -main() -{ - if [ -z "$1" ] - then - theme - printf '\033]P0000000\033]P7aaaaaa\033[J\n Theme number: ' - read -r number - else - number="$1" - fi - - - theme "$number" - printf '\033[J' -} - -main "$@" +printf '\033[J' diff --git a/bin/update-agenda b/bin/update-agenda @@ -1,7 +1,7 @@ #!/bin/sh url='https://intra.epitech.eu/auth-251e3d0bfcea8ed69a5581361a6a5b8b7ac3cfd5/planning/load?format=ical&location=FR/REN&onlymypromo=true&onlymymodule=true&semester=0,1,10,2,3,4,5,6,7,8,9' -curl -#L "$url" | agenda import - epitech +01 +curl -#L "${url}" | agenda import - epitech +01 url='https://fosdem.org/2018/schedule/ical' -curl -#L "$url" | agenda import - fosdem +01 +curl -#L "${url}" | agenda import - fosdem +01 diff --git a/dot/profile b/dot/profile @@ -1,11 +1,11 @@ export NAME='Josuah Demangeon' export TZ='Europe/Paris' export NICK='josuah' +export EMAIL='mail@josuah.net' +export MAILTO="${EMAIL}" -export EDITOR='edit' -export ISUAL='edit' -export PAGER='less' -export MANPAGER='less' +export EDITOR='vi' VISUAL='vi' +export PAGER='less' MANPAGER='less' export LANG='en_US.UTF-8' export LC_LC_COLLATE='C' @@ -20,10 +20,7 @@ export RUN="${HOME}/.cache/run" export LOG="${HOME}/.cache/log" export ETC="${HOME}/.config" -export EMAIL='mail@josuah.net' -export MAILTO="${EMAIL}" export MAIL="${VAR}/mail/mbox" -export MAILDIR="${VAR}/mail" export PLAN9="${HOME}/.local/src/plan9" export PATH="${HOME}/etc/bin:${HOME}/.local/bin:${PATH}:${PLAN9}/bin"