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 be6e074e78a4f6e482bbaa816ee92b769ad8e2d1
parent 8d61c3a8cf334bcd3d2e420df8e18ae9c3b5b32f
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 20 Sep 2018 12:57:25 +0200

Add bookmarking script

Diffstat:
Alinks/bin/bookmark | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+), 0 deletions(-)

diff --git a/links/bin/bookmark b/links/bin/bookmark @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +remoteuser=ad +hostname=idkfa.ucsd.edu +remotefile=/home/ad/doc/bookmark.md +hostfile="$remoteuser@$hostname:$remotefile" + +function help { + echo "Usage: ${0##*/} [OPTION] [COMMAND | URL]" +} + +function init { + ssh -q "$remoteuser@$hostname" -t \ + "mkdir -p $(dirname $remotefile) && touch $remotefile" +} + +function clear { + read -p "Really delete all bookmarks? [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + ssh -q "$remoteuser@$hostname" -t "rm $remotefile" + else + exit 1 + fi +} + +function edit { + vim "scp://$remoteuser@$hostname$remotefile" +} + +function printall { + tmp=$(mktemp) + scp -q "$hostfile" "$tmp" + cat "$tmp" +} + +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" +} + +[ $# -eq 0 ] && help && exit 0 + +case "$1" in + init) + init + ;; + edit) + edit + ;; + show) + printall + ;; + -h | --help) + help + exit 0 + ;; + add) + add "${*:2}" + ;; + clear) + clear + init + ;; + *) + add "${*:1}" +esac