bookmark (1406B)
1 #!/bin/sh 2 set -eu 3 4 localfile="$HOME/doc/bookmark.txt" 5 remoteuser=ad 6 hostname=adamsgaard.dk 7 remotefile="/home/$remoteuser/doc/bookmark.txt" 8 9 help() { 10 echo "Usage: ${0##*/} [OPTION | COMMAND [URL]]" 11 } 12 13 init() { 14 mkdir -p "$(dirname "$localfile")" 15 touch "$localfile" 16 ssh -q "$remoteuser@$hostname" -t \ 17 "mkdir -p $(dirname $remotefile) && touch $remotefile" 18 } 19 20 upload() { 21 scp -q \ 22 "$localfile" \ 23 "$remoteuser@$hostname:$remotefile" 24 } 25 26 download() { 27 scp -q \ 28 "$remoteuser@$hostname:$remotefile" \ 29 "$localfile" 30 } 31 32 clear() { 33 while :; do 34 printf "%s" "Really delete all bookmarks? [y/N] " 35 read -r yn 36 case $yn in 37 [Yy]*) 38 rm "$localfile" 39 ssh -q "$remoteuser@$hostname" -t "rm $remotefile"; 40 break;; 41 *) 42 exit 1;; 43 esac 44 done 45 } 46 47 edit() { 48 "$EDITOR" "$localfile" 49 } 50 51 printall() { 52 cat "$localfile" 53 } 54 55 exporthtml() { 56 echo "<!DOCTYPE html>" 57 echo "<html><head>" 58 echo "<title>Bookmarks</title>" 59 echo "<meta charset='utf-8'>" 60 echo "</head><body>" 61 62 printall | \ 63 sed 's/ /">/' | \ 64 sed 's/^/<a href="/' | \ 65 sed 's/$/<\/a><\/br>/' 66 echo "</body></html>" 67 } 68 69 add() { 70 echo "$@" >> "$localfile" 71 } 72 73 [ $# -eq 0 ] && help && exit 0 74 75 case "$1" in 76 -h | --help) 77 help 78 ;; 79 init) 80 init 81 ;; 82 edit) 83 download 84 edit 85 upload 86 ;; 87 list) 88 download 89 printall 90 ;; 91 clear) 92 clear 93 init 94 ;; 95 exporthtml) 96 exporthtml 97 ;; 98 *) 99 download 100 add "$@" 101 upload 102 esac 103 exit 0