Zet 926 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. zpath="$HOME/lib/zettelkasten/"
  3. mkdir -p "$zpath"
  4. visual=0
  5. names=0
  6. case $1 in
  7. -q) visual=1; shift;;
  8. -l) names=1; shift;;
  9. esac
  10. name="$*"
  11. [ -z "$name" ] &&
  12. links="$(for i in $(ls -1 $zpath); do printf '%s %s\n' $(basename $i) "$(sed -n '2p' $zpath/$i)";done | \
  13. dmenu -l 30 | sed 's/ +.*//g')"
  14. [ "$names" = "1" ] && { for link in $links; do printf "[%s]\n" $link; done | xsel -pi; exit; }
  15. date="$(date +%d%b%y-%H%M)"
  16. [ -f $zpath/$links ] && { filepath="$zpath/$links"; filename="$links"; } || \
  17. {
  18. [ -z "$name" ] && name="$links"
  19. filename="$date"-"$(echo "$name" | tr -cd '[:print:]' | tr ' ' '_' )"
  20. filepath="$zpath/$filename"
  21. printf '[%s] - %s' "$(date +%d%b%y-%H%M)" "$name" > $filepath
  22. cat << EOF >> $filepath
  23. REFERENCES:
  24. LINKS:
  25. ---
  26. EOF
  27. }
  28. [ $visual -eq 1 ] && { [ -t 1 ] && vis "$filepath" || vis -e nano "$filepath" ; } || E $filepath:2
  29. cd "$zpath"
  30. git add "$filename"
  31. git commit -m "Added $filename"