diff --git a/CHANGES.md b/CHANGES.md index e33b299..3365d87 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,8 @@ - autojump now uses ~/Library/autojump for storing data on OS X instead of incorrectly using Linux's $XDG_DATA_HOME. Existing data should automatically be migrated to the new location. +- Past behavior jumped to the highest weight database entry when not passed any + arguments. The new behavior is to stay in the current directory. ### Release v21.6.8: diff --git a/bin/autojump b/bin/autojump index ebfb4f6..29bb2a8 100755 --- a/bin/autojump +++ b/bin/autojump @@ -182,7 +182,10 @@ def find_matches(entries, needles): [Entry('.', 0)])) -def handle_no_arguments(needle, needles, entries): +def handle_tab_completion(needle, entries): + if not needle: + sys.exit(0) + tab_needle, path = get_tab_needle_and_path(needle, TAB_SEPARATOR) if path: @@ -195,8 +198,11 @@ def handle_no_arguments(needle, needles, entries): take(TAB_ENTRIES_COUNT, find_matches(entries, tab_needle)), TAB_SEPARATOR) else: - print(encode_local(surround_quotes( - first(find_matches(entries, needles)).path))) + print_tab_menu( + needle, + take(TAB_ENTRIES_COUNT, find_matches(entries, needle)), + TAB_SEPARATOR) + def match_anywhere(needles, haystack, ignore_case=False): @@ -333,11 +339,9 @@ def main(args): if args.add: save(config, first(add_path(load(config), args.add))) elif args.complete: - needle = first(sanitize(args.directory)) - tab_entries = take( - TAB_ENTRIES_COUNT, - find_matches(entriefy(load(config)), needle)) - print_tab_menu(needle, tab_entries, TAB_SEPARATOR) + handle_tab_completion( + needle=first(sanitize(args.directory)), + entries=entriefy(load(config))) elif args.decrease: data, entry = decrease_path(load(config), get_pwd(), args.decrease) save(config, data) @@ -360,8 +364,14 @@ def main(args): else: entries = entriefy(load(config)) needles = sanitize(args.directory) - needle = first(needles) - handle_no_arguments(needle, needles, entries) + _, path = get_tab_needle_and_path(first(needles), TAB_SEPARATOR) + + if path: + # found complete tab completion entry + print(encode_local(surround_quotes(path))) + else: + print(encode_local(surround_quotes( + first(find_matches(entries, needles))).path)) return 0 diff --git a/bin/autojump.zsh b/bin/autojump.zsh index 95f4312..df35e7e 100644 --- a/bin/autojump.zsh +++ b/bin/autojump.zsh @@ -1,15 +1,4 @@ -# determine the data directory according to the XDG Base Directory Specification -if [[ -n ${XDG_DATA_HOME} ]] && [[ ${XDG_DATA_HOME} == *${USER}* ]]; then - export AUTOJUMP_DATA_DIR="${XDG_DATA_HOME}/autojump" -else - export AUTOJUMP_DATA_DIR=${HOME}/.local/share/autojump -fi - -if [[ ! -e ${AUTOJUMP_DATA_DIR} ]]; then - mkdir -p "${AUTOJUMP_DATA_DIR}" -fi - -# set paths if necessary for local installations +# set paths for user installations if [[ -d ${HOME}/.autojump ]]; then path=(${HOME}/.autojump/bin ${path}) fpath=(${HOME}/.autojump/functions/ ${fpath}) @@ -20,20 +9,16 @@ command -v brew &>/dev/null \ && [[ -d "`brew --prefix`/share/zsh/site-functions" ]] \ && fpath=(`brew --prefix`/share/zsh/site-functions ${fpath}) +# add change pwd hook autojump_chpwd() { - if [[ "${AUTOJUMP_KEEP_SYMLINKS}" == "1" ]]; then - _PWD_ARGS="" - else - _PWD_ARGS="-P" - fi - { (autojump -a "$(pwd ${_PWD_ARGS})"&)>/dev/null 2>>|${AUTOJUMP_DATA_DIR}/autojump_errors ; } 2>/dev/null + (autojump -a "$(pwd)" &) &>/dev/null } typeset -gaU chpwd_functions chpwd_functions+=autojump_chpwd +# default autojump command j() { - # Cannot use =~ due to MacPorts zsh v4.2, see issue #125. if [[ ${@} == -* ]]; then autojump ${@} return @@ -50,46 +35,45 @@ j() { fi } +# jump to child directory (subdirectory of current path) jc() { if [[ ${@} == -* ]]; then - j ${@} - else - j $(pwd)/ ${@} - fi -} - -jo() { - if [[ ${@} == -* ]]; then - j ${@} + autojump ${@} return fi - if [ -z $(autojump $@) ]; then - echo "autojump: directory '${@}' not found" - echo "Try \`autojump --help\` for more information." - false - else - case ${OSTYPE} in - linux-gnu) - xdg-open "$(autojump $@)" - ;; - darwin*) - open "$(autojump $@)" - ;; - cygwin) - cygstart "" $(cygpath -w -a $(pwd)) - ;; - *) - echo "Unknown operating system." 1>&2 - ;; - esac - fi + j $(pwd)/ ${@} } +# open autojump results in file browser +jo() { + if [[ ${@} == -* ]]; then + autojump ${@} + return + fi + + case ${OSTYPE} in + linux-gnu) + xdg-open "$(autojump $@)" + ;; + darwin*) + open "$(autojump $@)" + ;; + cygwin) + cygstart "" $(cygpath -w -a $(pwd)) + ;; + *) + echo "Unknown operating system." 1>&2 + ;; + esac +} + +# open autojump results (child directory) in file browser jco() { if [[ ${@} == -* ]]; then - j ${@} - else - jo $(pwd) ${@} + autojump ${@} + return fi + + jo $(pwd)/ ${@} } diff --git a/bin/autojump_utils.py b/bin/autojump_utils.py index 64ad0f1..a29ad68 100644 --- a/bin/autojump_utils.py +++ b/bin/autojump_utils.py @@ -65,17 +65,22 @@ def get_tab_needle_and_path(tab_entry, separator): [needle]__[index]__[path] """ - matches = re.search( - r'(.*?)' + - separator + - r'[0-9]{1}' + - separator + - r'(.*)', + match_needle = re.search(r'(.*?)' + separator, tab_entry) + match_path = re.search( + separator + r'[0-9]{1}' + separator + r'(.*)', tab_entry) - if matches: - return matches.groups() - return None, None + if match_needle: + tab_needle = match_needle.group(1) + else: + tab_needle = None + + if match_path: + path = match_path.group(1) + else: + path = None + + return tab_needle, path def get_pwd():