Makes sure that autojump is sourced before running.

Fixes #255.
pull/319/head
William Ting 10 years ago
parent fe5f78fe43
commit 819c5c76cc

@ -46,9 +46,10 @@ from autojump_data import Entry
from autojump_data import load from autojump_data import load
from autojump_data import save from autojump_data import save
from autojump_utils import first from autojump_utils import first
from autojump_utils import get_tab_entry_info
from autojump_utils import get_pwd from autojump_utils import get_pwd
from autojump_utils import get_tab_entry_info
from autojump_utils import has_uppercase from autojump_utils import has_uppercase
from autojump_utils import is_autojump_sourced
from autojump_utils import is_osx from autojump_utils import is_osx
from autojump_utils import is_windows from autojump_utils import is_windows
from autojump_utils import last from autojump_utils import last
@ -59,7 +60,7 @@ from autojump_utils import sanitize
from autojump_utils import take from autojump_utils import take
from autojump_utils import unico from autojump_utils import unico
VERSION = '22.1.0-beta' VERSION = '22.1.1-beta'
FUZZY_MATCH_THRESHOLD = 0.6 FUZZY_MATCH_THRESHOLD = 0.6
TAB_ENTRIES_COUNT = 9 TAB_ENTRIES_COUNT = 9
TAB_SEPARATOR = '__' TAB_SEPARATOR = '__'
@ -350,6 +351,12 @@ def print_stats(data, data_path):
def main(args): # noqa def main(args): # noqa
if not is_autojump_sourced() and not is_windows():
print("Please source the correct autojump file in your shell's")
print("startup file. For more information, please reinstall autojump")
print("and read the post installation instructions.")
return 1
config = set_defaults() config = set_defaults()
# all arguments are mutually exclusive # all arguments are mutually exclusive

@ -1,3 +1,5 @@
export AUTOJUMP_SOURCED=1
# set user installation paths # set user installation paths
if [[ -d ~/.autojump/ ]]; then if [[ -d ~/.autojump/ ]]; then
export PATH=~/.autojump/bin:"${PATH}" export PATH=~/.autojump/bin:"${PATH}"
@ -57,12 +59,13 @@ j() {
return return
fi fi
new_path="$(autojump ${@})" output="$(autojump ${@})"
if [[ -d "${new_path}" ]]; then if [[ -d "${output}" ]]; then
echo -e "\\033[31m${new_path}\\033[0m" echo -e "\\033[31m${output}\\033[0m"
cd "${new_path}" cd "${output}"
else else
echo "autojump: directory '${@}' not found" echo "autojump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information." echo "Try \`autojump --help\` for more information."
false false
fi fi
@ -86,17 +89,17 @@ jo() {
return return
fi fi
new_path="$(autojump ${@})" output="$(autojump ${@})"
if [[ -d "${new_path}" ]]; then if [[ -d "${output}" ]]; then
case ${OSTYPE} in case ${OSTYPE} in
linux-gnu) linux-gnu)
xdg-open "${new_path}" xdg-open "${output}"
;; ;;
darwin*) darwin*)
open "${new_path}" open "${output}"
;; ;;
cygwin) cygwin)
cygstart "" $(cygpath -w -a ${new_path}) cygstart "" $(cygpath -w -a ${output})
;; ;;
*) *)
echo "Unknown operating system." 1>&2 echo "Unknown operating system." 1>&2
@ -104,6 +107,7 @@ jo() {
esac esac
else else
echo "autojump: directory '${@}' not found" echo "autojump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information." echo "Try \`autojump --help\` for more information."
false false
fi fi

@ -1,3 +1,5 @@
set -x AUTOJUMP_SOURCED 1
# set user installation path # set user installation path
if test -d ~/.autojump if test -d ~/.autojump
set -x PATH ~/.autojump/bin $PATH set -x PATH ~/.autojump/bin $PATH
@ -31,26 +33,22 @@ function __aj_err
echo $argv 1>&2; false echo $argv 1>&2; false
end end
function __aj_not_found
__aj_err "autojump: directory '"$argv"' not found"
__aj_err "Try `autojump --help` for more information."
end
# default autojump command # default autojump command
function j function j
switch "$argv" switch "$argv"
case '-*' '--*' case '-*' '--*'
autojump $argv autojump $argv
case '*' case '*'
set -l new_path (autojump $argv) set -l output (autojump $argv)
if test -d "$new_path" if test -d "$output"
set_color red set_color red
echo $new_path echo $output
set_color normal set_color normal
cd $new_path cd $output
else else
__aj_not_found $argv __aj_err "autojump: directory '"$argv"' not found"
__aj_err "\n$output\n"
__aj_err "Try `autojump --help` for more information."
end end
end end
end end
@ -69,8 +67,11 @@ end
# open autojump results in file browser # open autojump results in file browser
function jo function jo
if test -z (autojump $argv) set -l output (autojump $argv)
__aj_not_found $argv if test -d "$output"
__aj_err "autojump: directory '"$argv"' not found"
__aj_err "\n$output\n"
__aj_err "Try `autojump --help` for more information."
else else
switch (sh -c 'echo ${OSTYPE}') switch (sh -c 'echo ${OSTYPE}')
case linux-gnu case linux-gnu

@ -1,3 +1,5 @@
export AUTOJUMP_SOURCED=1
# set user installation paths # set user installation paths
if [[ -d ~/.autojump/bin ]]; then if [[ -d ~/.autojump/bin ]]; then
path=(~/.autojump/bin ${path}) path=(~/.autojump/bin ${path})
@ -48,12 +50,13 @@ j() {
fi fi
setopt localoptions noautonamedirs setopt localoptions noautonamedirs
local new_path="$(autojump ${@})" local output="$(autojump ${@})"
if [[ -d "${new_path}" ]]; then if [[ -d "${output}" ]]; then
echo -e "\\033[31m${new_path}\\033[0m" echo -e "\\033[31m${output}\\033[0m"
cd "${new_path}" cd "${output}"
else else
echo "autojump: directory '${@}' not found" echo "autojump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information." echo "Try \`autojump --help\` for more information."
false false
fi fi
@ -78,17 +81,17 @@ jo() {
fi fi
setopt localoptions noautonamedirs setopt localoptions noautonamedirs
local new_path="$(autojump ${@})" local output="$(autojump ${@})"
if [[ -d "${new_path}" ]]; then if [[ -d "${output}" ]]; then
case ${OSTYPE} in case ${OSTYPE} in
linux-gnu) linux-gnu)
xdg-open "${new_path}" xdg-open "${output}"
;; ;;
darwin*) darwin*)
open "${new_path}" open "${output}"
;; ;;
cygwin) cygwin)
cygstart "" $(cygpath -w -a ${new_path}) cygstart "" $(cygpath -w -a ${output})
;; ;;
*) *)
echo "Unknown operating system." 1>&2 echo "Unknown operating system." 1>&2
@ -96,6 +99,7 @@ jo() {
esac esac
else else
echo "autojump: directory '${@}' not found" echo "autojump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information." echo "Try \`autojump --help\` for more information."
false false
fi fi

@ -89,6 +89,10 @@ def in_bash():
return 'bash' in os.getenv('SHELL') return 'bash' in os.getenv('SHELL')
def is_autojump_sourced():
return '1' == os.getenv('AUTOJUMP_SOURCED')
def is_python2(): def is_python2():
return sys.version_info[0] == 2 return sys.version_info[0] == 2

@ -136,7 +136,7 @@ def parse_arguments(): # noqa
return args return args
def print_post_installation_message(etc_dir, share_dir, bin_dir): def show_post_installation_message(etc_dir, share_dir, bin_dir):
if platform.system() == 'Windows': if platform.system() == 'Windows':
print("\nPlease manually add %s to your user path" % bin_dir) print("\nPlease manually add %s to your user path" % bin_dir)
else: else:
@ -209,7 +209,7 @@ def main(args):
if args.custom_install: if args.custom_install:
modify_autojump_sh(etc_dir, args.dryrun) modify_autojump_sh(etc_dir, args.dryrun)
print_post_installation_message(etc_dir, share_dir, bin_dir) show_post_installation_message(etc_dir, share_dir, bin_dir)
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save