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.

130 lines
2.9 KiB

пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 11 година
пре 11 година
пре 10 година
пре 8 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 10 година
пре 10 година
пре 11 година
пре 10 година
пре 10 година
  1. export AUTOJUMP_SOURCED=1
  2. # set user installation paths
  3. if [[ -d ~/.autojump/ ]]; then
  4. export PATH=~/.autojump/bin:"${PATH}"
  5. fi
  6. # set error file location
  7. if [[ "$(uname)" == "Darwin" ]]; then
  8. export AUTOJUMP_ERROR_PATH=~/Library/autojump/errors.log
  9. elif [[ -n "${XDG_DATA_HOME}" ]]; then
  10. export AUTOJUMP_ERROR_PATH="${XDG_DATA_HOME}/autojump/errors.log"
  11. else
  12. export AUTOJUMP_ERROR_PATH=~/.local/share/autojump/errors.log
  13. fi
  14. if [[ ! -d "$(dirname ${AUTOJUMP_ERROR_PATH})" ]]; then
  15. mkdir -p "$(dirname ${AUTOJUMP_ERROR_PATH})"
  16. fi
  17. # enable tab completion
  18. _autojump() {
  19. local cur
  20. cur=${COMP_WORDS[*]:1}
  21. comps=$(autojump --complete $cur)
  22. while read i; do
  23. COMPREPLY=("${COMPREPLY[@]}" "${i}")
  24. done <<EOF
  25. $comps
  26. EOF
  27. }
  28. complete -F _autojump j
  29. # change pwd hook
  30. autojump_add_to_database() {
  31. if [[ -f "${AUTOJUMP_ERROR_PATH}" ]]; then
  32. (autojump --add "$(pwd)" >/dev/null 2>>${AUTOJUMP_ERROR_PATH} &) &>/dev/null
  33. else
  34. (autojump --add "$(pwd)" >/dev/null &) &>/dev/null
  35. fi
  36. }
  37. case $PROMPT_COMMAND in
  38. *autojump*)
  39. ;;
  40. *)
  41. PROMPT_COMMAND="${PROMPT_COMMAND:+$(echo "${PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }autojump_add_to_database"
  42. ;;
  43. esac
  44. # default autojump command
  45. j() {
  46. if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
  47. autojump ${@}
  48. return
  49. fi
  50. output="$(autojump ${@})"
  51. if [[ -d "${output}" ]]; then
  52. if [ -t 1 ]; then # if stdout is a terminal, use colors
  53. echo -e "\\033[31m${output}\\033[0m"
  54. else
  55. echo -e "${output}"
  56. fi
  57. cd "${output}"
  58. else
  59. echo "autojump: directory '${@}' not found"
  60. echo "\n${output}\n"
  61. echo "Try \`autojump --help\` for more information."
  62. false
  63. fi
  64. }
  65. # jump to child directory (subdirectory of current path)
  66. jc() {
  67. if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
  68. autojump ${@}
  69. return
  70. else
  71. j $(pwd) ${@}
  72. fi
  73. }
  74. # open autojump results in file browser
  75. jo() {
  76. if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
  77. autojump ${@}
  78. return
  79. fi
  80. output="$(autojump ${@})"
  81. if [[ -d "${output}" ]]; then
  82. case ${OSTYPE} in
  83. linux*)
  84. xdg-open "${output}"
  85. ;;
  86. darwin*)
  87. open "${output}"
  88. ;;
  89. cygwin)
  90. cygstart "" $(cygpath -w -a ${output})
  91. ;;
  92. *)
  93. echo "Unknown operating system: ${OSTYPE}." 1>&2
  94. ;;
  95. esac
  96. else
  97. echo "autojump: directory '${@}' not found"
  98. echo "\n${output}\n"
  99. echo "Try \`autojump --help\` for more information."
  100. false
  101. fi
  102. }
  103. # open autojump results (child directory) in file browser
  104. jco() {
  105. if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
  106. autojump ${@}
  107. return
  108. else
  109. jo $(pwd) ${@}
  110. fi
  111. }