Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. if which fasd >/dev/null; then
  2. # install fasd hooks and basic aliases in the shell
  3. eval "$(fasd --init auto)"
  4.  
  5. # if there is fzf available use it to search fasd results
  6. if which fzf >/dev/null; then
  7.  
  8. alias v >/dev/null && unalias v
  9. alias vd >/dev/null && unalias vd
  10. alias z >/dev/null && unalias z
  11.  
  12. # edit given file or search in recently used files
  13. function v {
  14. local file
  15. # if arg1 is a path to existing file then simply open it in the editor
  16. test -e "$1" && $EDITOR "$@" && return
  17. # else use fasd and fzf to search for recent files
  18. file="$(fasd -Rfl "$*" | fzf -1 -0 --no-sort +m)" && $EDITOR "${file}" || $EDITOR "$@"
  19. }
  20.  
  21. # cd into the directory containing a recently used file
  22. function vd {
  23. local dir
  24. local file
  25. file="$(fasd -Rfl "$*" | fzf -1 -0 --no-sort +m)" && dir=$(dirname "$file") && cd "$dir"
  26. }
  27.  
  28. # cd into given dir or search in recently used dirs
  29. function z {
  30. [ $# -eq 1 ] && test -d "$1" && cd "$1" && return
  31. local dir
  32. dir="$(fasd -Rdl "$*" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
  33. }
  34. fi
  35. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement