dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 868eb693af36369d75d0d7aeba01533c3aadfc77
parent befe26db2683fede86e7b1cf39db2b0324c58e2b
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 12 Jun 2019 13:14:01 +0200

Rework bookmark script for POSIX sh

Diffstat:
M.local/bin/bookmark | 51+++++++++++++++++++++++++--------------------------
1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/.local/bin/bookmark b/.local/bin/bookmark @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -e +#!/bin/sh +set -eu localfile="$HOME/doc/bookmark.txt" remoteuser=ad @@ -7,51 +7,55 @@ hostname=adamsgaard.dk remotefile="/home/$remoteuser/doc/bookmark.txt" port=12346 -function help { +help() { echo "Usage: ${0##*/} [OPTION | COMMAND [URL]]" } -function init { +init() { mkdir -p "$(dirname "$localfile")" touch "$localfile" ssh -p "$port" -q "$remoteuser@$hostname" -t \ "mkdir -p $(dirname $remotefile) && touch $remotefile" } -function upload { +upload() { scp -q \ -P "$port" \ "$localfile" \ "$remoteuser@$hostname:$remotefile" } -function download { +download() { scp -q \ -P "$port" \ "$remoteuser@$hostname:$remotefile" \ "$localfile" } -function clear { - read -p "Really delete all bookmarks? [y/N] " -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - rm "$localfile" - ssh -q "$remoteuser@$hostname" -t "rm $remotefile" - else - exit 1 - fi +clear() { + while :; do + printf "%s" "Really delete all bookmarks? [y/N] " + read -r yn + case $yn in + [Yy]*) + rm "$localfile" + ssh -q "$remoteuser@$hostname" -t "rm $remotefile"; + break;; + *) + exit 1;; + esac + done } -function edit { +edit() { "$EDITOR" "$localfile" } -function printall { +printall() { cat "$localfile" } -function exporthtml { +exporthtml() { echo "<!DOCTYPE html>" echo "<html><head>" echo "<title>Bookmarks</title>" @@ -66,8 +70,8 @@ function exporthtml { echo "</body></html>" } -function add { - echo "$@" >> $localfile +add() { + echo "$@" >> "$localfile" } [ $# -eq 0 ] && help && exit 0 @@ -95,14 +99,9 @@ case "$1" in exporthtml) exporthtml ;; - add) - download - add "${*:2}" - upload - ;; *) download - add "${*:1}" + add "$@" upload esac exit 0