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.

48 line
1.8 KiB

15 年之前
15 年之前
  1. #Copyright Joel Schaerer 2008, 2009
  2. #This file is part of autojump
  3. #autojump is free software: you can redistribute it and/or modify
  4. #it under the terms of the GNU General Public License as published by
  5. #the Free Software Foundation, either version 3 of the License, or
  6. #(at your option) any later version.
  7. #
  8. #autojump is distributed in the hope that it will be useful,
  9. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. #GNU General Public License for more details.
  12. #
  13. #You should have received a copy of the GNU General Public License
  14. #along with autojump. If not, see <http://www.gnu.org/licenses/>.
  15. #This shell snippet sets the prompt command and the necessary aliases
  16. _autojump()
  17. {
  18. local cur
  19. cur=${COMP_WORDS[*]:1}
  20. while read i
  21. do
  22. COMPREPLY=("${COMPREPLY[@]}" "${i}")
  23. done < <(autojump --bash --completion $cur)
  24. }
  25. complete -F _autojump j
  26. data_dir=${XDG_DATA_HOME:-$([ -e ~/.local/share ] && echo ~/.local/share || echo ~)}
  27. if [ "$data_dir" = "~" ]
  28. then
  29. export AUTOJUMP_DATA_DIR=${data_dir}
  30. else
  31. export AUTOJUMP_DATA_DIR=${data_dir}/autojump
  32. fi
  33. if [ ! -e "${AUTOJUMP_DATA_DIR}" ]
  34. then
  35. mkdir "${AUTOJUMP_DATA_DIR}"
  36. mv ~/.autojump_py "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration
  37. mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null
  38. mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null
  39. fi
  40. AUTOJUMP='{ (autojump -a "$(pwd -P)"&)>/dev/null 2>>${AUTOJUMP_DATA_DIR}/.autojump_errors;} 2>/dev/null'
  41. if [[ ! $PROMPT_COMMAND =~ autojump ]]; then
  42. export PROMPT_COMMAND="${PROMPT_COMMAND:-:} && $AUTOJUMP"
  43. fi
  44. alias jumpstat="autojump --stat"
  45. function j { new_path="$(autojump $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path";fi }