Posted to tcl by aku at Wed Mar 02 17:00:24 GMT 2011view raw

  1. # -*- sh -*-
  2.  
  3. function f_hilit ()
  4. {
  5. sed \
  6. -e 's|\*CURRENT\*| [01;37;41m*CURRENT* [00m|g' \
  7. -e 's|\*MERGE\*| [01;34m*MERGE* [00m|g' \
  8. -e 's|\*BRANCH\*| [01;32;40m*BRANCH* [00m|g' \
  9. -e 's|\[\([0-9a-z]*\)\]|[ [05m\1 [00m]|g'
  10. }
  11.  
  12. function f ()
  13. {
  14. rm $$.* 2> /dev/null
  15.  
  16. cmd="$1"
  17. shift
  18. case "$cmd" in
  19. ch)
  20. clear
  21. echo
  22. fossil extra > $$.extra
  23. for pattern in $(cat $HOME/.fossil.ignore 2>/dev/null) $$.*
  24. do
  25. grep -v "$pattern" $$.extra > $$.kept
  26. mv $$.kept $$.extra
  27. done
  28. sed < $$.extra -e 's|^|EXTRA |'
  29. echo
  30. rm $$.extra
  31. fossil changes
  32. ;;
  33. delta)
  34. fossil changes|grep EDITED|awk '{ print $2 }' > $$.edited
  35. if test "X$1" != "X" ; then
  36. grep "$1" $$.edited|xargs -n1 fossil gdiff
  37. else
  38. cat $$.edited|xargs -n1 fossil gdiff
  39. fi
  40. rm $$.edited
  41. ;;
  42. hi)
  43. clear
  44. echo
  45. fossil timeline $*|f_hilit
  46. ;;
  47. co)
  48. echo "$1" > $$.M;
  49. shift;
  50. eval fossil commit -M $$.M "$*";
  51. rm $$.M
  52. ;;
  53. coe)
  54. echo '' > $$.M;
  55. echo '# Commit message' >> $$.M;
  56. fossil extra | sed -e 's|^|#EXTRA |' >> $$.M;
  57. echo '' >> $$.M;
  58. fossil changes | sed -e 's|^|#|' >> $$.M;
  59. echo;
  60. vi $$.M;
  61. grep -v '^#' $$.M > $$$.MF;
  62. eval fossil commit -M $$.MF "$*";
  63. rm $$.M $$.MF
  64. ;;
  65. up)
  66. clear
  67. echo
  68. fossil update
  69. echo
  70. fossil timeline|f_hilit
  71. echo
  72. ;;
  73. help)
  74. clear
  75. echo
  76. fossil help $*
  77. echo
  78. ;;
  79. *)
  80. # BAD. Quoting broken. Rather, the $* needs some form of
  81. # quoting to protect arguments with spaces in them. A
  82. # simple "$*" however is not the right way of doing that.
  83. eval fossil "$cmd $*"
  84. ;;
  85. esac
  86. }

Comments

Posted by evilotto at Fri Mar 04 03:29:21 GMT 2011 [text] [code]

use "$@" to have the shell quote things with spaces properly