qs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. # qs, stands for Quick Script
  3. # useful so that you can just do M-x qs, <number>, <ret>, and it'll
  4. # run that command. This is the simple alternative to allowing for
  5. # adding in quick commands in ait(1).
  6. #
  7. # Two notes:
  8. # 1. this can only be ran in a shell by piping a value or entering
  9. # one in if ran. Ex: $ echo "" | qs
  10. # 2. You can pass arguments for the program you want to run. For
  11. # example, if you want to run sort(1) but this time you want to
  12. # pass the -n flag you could do: M-x qs -n
  13. #
  14. # Generally, the way this is useful is that you keep qs as the default
  15. # command for shell-command or open-command then you would just do a
  16. # `esc x` <ret> number <ret> which is pretty quick compaired to typing
  17. # it out but probably not as quick as a keybinding.
  18. #
  19. # requires pick(1) to be installed
  20. value=""
  21. # turns out read(1) doesn't like newlines and the -d flag isn't
  22. # in bourne shell
  23. if test -p /dev/stdin; then
  24. while IFS= read -r line; do
  25. if test "$value" = ""; then
  26. value="$line"
  27. else
  28. value="$value\n$line"
  29. fi
  30. done
  31. fi
  32. output=`cat <<EOF
  33. 1. align
  34. 2. ff
  35. 3. fmt -w 70
  36. 4. gff
  37. 5. gg
  38. 6. ggt
  39. 7. spell
  40. 8. sort
  41. 9. xclip -selection clipboard
  42. EOF`
  43. cmd=`echo "$output" | pick | cut -d' ' -f2-`
  44. echo "$value" | $cmd $@