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 2412351bbac792ec7156036f4b1b40fd871e0e27
parent 574616375c0bcc1de83ff69a83ba47b11cec29a9
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 20 Sep 2018 14:32:57 +0200

Merge branch 'master' of gitlab.com:admesg/dotfiles

Diffstat:
Mlinks/bin/bookmark | 57++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/links/bin/bookmark b/links/bin/bookmark @@ -1,23 +1,39 @@ #!/usr/bin/env bash +localfile="$HOME/doc/bookmark.txt" +remotefile=/home/ad/doc/bookmark.txt remoteuser=ad hostname=idkfa.ucsd.edu -remotefile=/home/ad/doc/bookmark.md hostfile="$remoteuser@$hostname:$remotefile" function help { - echo "Usage: ${0##*/} [OPTION] [COMMAND | URL]" + echo "Usage: ${0##*/} [OPTION | COMMAND [URL]]" } function init { + mkdir -p "$(dirname "$localfile")" + touch "$localfile" ssh -q "$remoteuser@$hostname" -t \ "mkdir -p $(dirname $remotefile) && touch $remotefile" } +function upload { + rsync -ra -e ssh \ + "$localfile" \ + "$remoteuser@$hostname:$remotefile" +} + +function download { + rsync -ra -e ssh \ + "$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 @@ -25,48 +41,47 @@ function clear { } function edit { - vim "scp://$remoteuser@$hostname$remotefile" + "$EDITOR" "$localfile" } function printall { - tmp=$(mktemp) - scp -q "$hostfile" "$tmp" - cat "$tmp" + cat "$localfile" } function add { - # for url in "$@"; do - # ssh "$remoteuser@$hostname" -t \ - # "echo '$url' >> $remotefile" - # done - #echo ssh -q "$remoteuser@$hostname" -t \ - ssh -q "$remoteuser@$hostname" -t \ - "for url in $@; do echo \"\$url\" >> $remotefile; done" + echo "$@" >> $localfile } [ $# -eq 0 ] && help && exit 0 case "$1" in + -h | --help) + help + ;; init) init ;; edit) + download edit + upload ;; - show) + list) + download printall ;; - -h | --help) - help - exit 0 - ;; - add) - add "${*:2}" - ;; clear) clear init ;; + add) + download + add "${*:2}" + upload + ;; *) + download add "${*:1}" + upload esac +exit 0