vimdot.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. # Written by: John Ellson <[email protected]>
  3. if [ "$1" = "-?" ]; then
  4. echo "Usage: vimdot [file]" >&2
  5. exit 0
  6. fi
  7. error() { echo "$0: $*" >&2; exit 1; }
  8. # Try $EDITOR first, else try vim or vi
  9. editor="$(which $EDITOR)" || editor="/usr/bin/vim"
  10. [ -x "$editor" ] || editor="/usr/bin/vi"
  11. [ -x "$editor" ] || error "EDITOR not found or not executable";
  12. default="noname.gv"
  13. if test -z "$1"; then
  14. f="$default"
  15. if ! test -f "$f"; then
  16. if ! test -w .; then error "directory `pwd` is not writable"; fi
  17. cat >"$f" <<EOF
  18. digraph G {
  19. graph [layout=dot rankdir=LR]
  20. // This is just an example for you to use as a template.
  21. // Edit as you like. Whenever you save a legal graph
  22. // the layout in the graphviz window will be updated.
  23. vim [href="http://www.vim.org/"]
  24. dot [href="http://www.graphviz.org/"]
  25. vimdot [href="file:///usr/bin/vimdot"]
  26. {vim dot} -> vimdot
  27. }
  28. EOF
  29. fi
  30. else
  31. f="$1"
  32. fi
  33. if ! test -w "$f"; then error "$f is not writable"; fi
  34. # dot -Txlib watches the file $f for changes using inotify()
  35. dot -Txlib "$f" 2>/dev/null &
  36. # open an editor on the file $f (could be any editor; gvim &'s itself)
  37. exec $editor "$f"