You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

elvmv 837B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env elvish
  2. fn list-items [a]{
  3. if (-is-dir $a) { put $a/* } else { put $a }
  4. }
  5. items = []
  6. if (== (count $args) 0) {
  7. items = [./*]
  8. } else {
  9. for i $args {
  10. if (eq $i '-') {
  11. each [x]{ items = [$@items (list-items $x)] }
  12. } else {
  13. items = [$@items (list-items $i)]
  14. }
  15. }
  16. }
  17. file = (mktemp -p /tmp elvmvXXXXX)
  18. print > $file
  19. for i $items {
  20. echo $i >> $file
  21. }
  22. editor = vi
  23. if (has-env VISUAL) {
  24. editor = $E:VISUAL
  25. } elif (has-env EDITOR) {
  26. editor = $E:EDITOR
  27. }
  28. fn abort [&code=1 a]{
  29. echo $a >&2
  30. rm $file
  31. exit $code
  32. }
  33. try {
  34. (external $editor) $file
  35. } except {
  36. abort 'Editor exited with error. Aborting...'
  37. }
  38. i = 0
  39. cat $file | each [l]{
  40. if (eq $l '') {
  41. rm $items[$i]
  42. } elif (not-eq $l $items[$i]) {
  43. mkdir -p (path-dir $l)
  44. mv $items[$i] $l
  45. }
  46. i = (+ $i 1)
  47. }
  48. rm $file