bookmark (1181B)
1 #!/usr/bin/env sh 2 3 check_env () { 4 if [ -z "$(printenv "$1")" ] 5 then 6 echo "You must set \$$1 variable $2" >&2 7 exit 1 8 fi 9 } 10 11 print_count () { 12 echo "Articles: $(wc -l < "$BOOKMARKS")" 13 } 14 15 print_help () { 16 echo "bookmark - script for keeping and retrieving your bookmarks 17 Usage: 18 bookmark add \"link\" 19 save link in bookmark file 20 bookmark ls 21 view bookmarks list in your \$PAGER 22 bookmark cat 23 print all you bookmarks to terminal 24 bookmark count 25 show number of your bookmarks 26 bookmark get 27 get first bookmark from list 28 " 29 } 30 31 if [ -z "$1" ] 32 then 33 print_help 34 exit 35 fi 36 37 BOOKMARKS=~/data/bookmarks 38 TEMP=~/data/bookmarks.temp 39 40 if [ "ls" = "$1" ] 41 then 42 check_env "PAGER" 43 $PAGER $BOOKMARKS 44 exit 45 fi 46 47 if [ "cat" = "$1" ] 48 then 49 cat $BOOKMARKS 50 exit 51 fi 52 53 if [ "count" = "$1" ] 54 then 55 print_count 56 exit 57 fi 58 59 if [ "get" = "$1" ] 60 then 61 head -n 1 $BOOKMARKS 62 tail -n +2 $BOOKMARKS > $TEMP; mv $TEMP $BOOKMARKS 63 exit 64 fi 65 66 if [ "add" = "$1" ] 67 then 68 if grep -qi "$2" $BOOKMARKS 69 then 70 exit 1 71 fi 72 echo "$2" >> $BOOKMARKS 73 exit 74 fi 75 76 echo "Unknown command" 77 print_help