Dotfiles for my tiling window manager + terminal workflow.
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.

57 lines
1.2 KiB

  1. #
  2. # Wrap the builtin cd command to maintain directory history.
  3. #
  4. function cd --description "Change directory"
  5. set -l MAX_DIR_HIST 25
  6. if test (count $argv) -gt 1
  7. printf "%s\n" (_ "Too many args for cd command")
  8. return 1
  9. end
  10. # Skip history in subshells.
  11. if status --is-command-substitution
  12. builtin cd $argv
  13. return $status
  14. end
  15. # Avoid set completions.
  16. set -l previous $PWD
  17. if test "$argv" = "-"
  18. if test "$__fish_cd_direction" = "next"
  19. nextd
  20. else
  21. prevd
  22. end
  23. return $status
  24. end
  25. # allow explicit "cd ." if the mount-point became stale in the meantime
  26. if test "$argv" = "."
  27. cd "$PWD"
  28. return $status
  29. end
  30. builtin cd $argv
  31. set -l cd_status $status
  32. if test $cd_status -eq 0 -a "$PWD" != "$previous"
  33. set -q dirprev
  34. or set -l dirprev
  35. set -q dirprev[$MAX_DIR_HIST]
  36. and set -e dirprev[1]
  37. set -g -a dirprev $previous
  38. set -e dirnext
  39. set -g __fish_cd_direction prev
  40. set -U last_dir $PWD
  41. {{ if (not (eq .linux_os "termux")) }}
  42. lsd -a
  43. {{ else }}
  44. ls -a
  45. {{ end }}
  46. end
  47. return $cd_status
  48. end