mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
Merge pull request #319 from wting/check_autojump_sourced
Makes sure that autojump is sourced before running.
This commit is contained in:
commit
e621603e46
11
bin/autojump
11
bin/autojump
@ -46,9 +46,10 @@ from autojump_data import Entry
|
||||
from autojump_data import load
|
||||
from autojump_data import save
|
||||
from autojump_utils import first
|
||||
from autojump_utils import get_tab_entry_info
|
||||
from autojump_utils import get_pwd
|
||||
from autojump_utils import get_tab_entry_info
|
||||
from autojump_utils import has_uppercase
|
||||
from autojump_utils import is_autojump_sourced
|
||||
from autojump_utils import is_osx
|
||||
from autojump_utils import is_windows
|
||||
from autojump_utils import last
|
||||
@ -59,7 +60,7 @@ from autojump_utils import sanitize
|
||||
from autojump_utils import take
|
||||
from autojump_utils import unico
|
||||
|
||||
VERSION = '22.1.0-beta'
|
||||
VERSION = '22.1.1-beta'
|
||||
FUZZY_MATCH_THRESHOLD = 0.6
|
||||
TAB_ENTRIES_COUNT = 9
|
||||
TAB_SEPARATOR = '__'
|
||||
@ -350,6 +351,12 @@ def print_stats(data, data_path):
|
||||
|
||||
|
||||
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()
|
||||
|
||||
# all arguments are mutually exclusive
|
||||
|
@ -1,3 +1,5 @@
|
||||
export AUTOJUMP_SOURCED=1
|
||||
|
||||
# set user installation paths
|
||||
if [[ -d ~/.autojump/ ]]; then
|
||||
export PATH=~/.autojump/bin:"${PATH}"
|
||||
@ -57,12 +59,13 @@ j() {
|
||||
return
|
||||
fi
|
||||
|
||||
new_path="$(autojump ${@})"
|
||||
if [[ -d "${new_path}" ]]; then
|
||||
echo -e "\\033[31m${new_path}\\033[0m"
|
||||
cd "${new_path}"
|
||||
output="$(autojump ${@})"
|
||||
if [[ -d "${output}" ]]; then
|
||||
echo -e "\\033[31m${output}\\033[0m"
|
||||
cd "${output}"
|
||||
else
|
||||
echo "autojump: directory '${@}' not found"
|
||||
echo "\n${output}\n"
|
||||
echo "Try \`autojump --help\` for more information."
|
||||
false
|
||||
fi
|
||||
@ -86,17 +89,17 @@ jo() {
|
||||
return
|
||||
fi
|
||||
|
||||
new_path="$(autojump ${@})"
|
||||
if [[ -d "${new_path}" ]]; then
|
||||
output="$(autojump ${@})"
|
||||
if [[ -d "${output}" ]]; then
|
||||
case ${OSTYPE} in
|
||||
linux-gnu)
|
||||
xdg-open "${new_path}"
|
||||
xdg-open "${output}"
|
||||
;;
|
||||
darwin*)
|
||||
open "${new_path}"
|
||||
open "${output}"
|
||||
;;
|
||||
cygwin)
|
||||
cygstart "" $(cygpath -w -a ${new_path})
|
||||
cygstart "" $(cygpath -w -a ${output})
|
||||
;;
|
||||
*)
|
||||
echo "Unknown operating system." 1>&2
|
||||
@ -104,6 +107,7 @@ jo() {
|
||||
esac
|
||||
else
|
||||
echo "autojump: directory '${@}' not found"
|
||||
echo "\n${output}\n"
|
||||
echo "Try \`autojump --help\` for more information."
|
||||
false
|
||||
fi
|
||||
|
@ -1,3 +1,5 @@
|
||||
set -x AUTOJUMP_SOURCED 1
|
||||
|
||||
# set user installation path
|
||||
if test -d ~/.autojump
|
||||
set -x PATH ~/.autojump/bin $PATH
|
||||
@ -31,26 +33,22 @@ function __aj_err
|
||||
echo $argv 1>&2; false
|
||||
end
|
||||
|
||||
function __aj_not_found
|
||||
__aj_err "autojump: directory '"$argv"' not found"
|
||||
__aj_err "Try `autojump --help` for more information."
|
||||
end
|
||||
|
||||
|
||||
# default autojump command
|
||||
function j
|
||||
switch "$argv"
|
||||
case '-*' '--*'
|
||||
autojump $argv
|
||||
case '*'
|
||||
set -l new_path (autojump $argv)
|
||||
if test -d "$new_path"
|
||||
set -l output (autojump $argv)
|
||||
if test -d "$output"
|
||||
set_color red
|
||||
echo $new_path
|
||||
echo $output
|
||||
set_color normal
|
||||
cd $new_path
|
||||
cd $output
|
||||
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
|
||||
@ -69,8 +67,11 @@ end
|
||||
|
||||
# open autojump results in file browser
|
||||
function jo
|
||||
if test -z (autojump $argv)
|
||||
__aj_not_found $argv
|
||||
set -l output (autojump $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
|
||||
switch (sh -c 'echo ${OSTYPE}')
|
||||
case linux-gnu
|
||||
|
@ -1,3 +1,5 @@
|
||||
export AUTOJUMP_SOURCED=1
|
||||
|
||||
# set user installation paths
|
||||
if [[ -d ~/.autojump/bin ]]; then
|
||||
path=(~/.autojump/bin ${path})
|
||||
@ -48,12 +50,13 @@ j() {
|
||||
fi
|
||||
|
||||
setopt localoptions noautonamedirs
|
||||
local new_path="$(autojump ${@})"
|
||||
if [[ -d "${new_path}" ]]; then
|
||||
echo -e "\\033[31m${new_path}\\033[0m"
|
||||
cd "${new_path}"
|
||||
local output="$(autojump ${@})"
|
||||
if [[ -d "${output}" ]]; then
|
||||
echo -e "\\033[31m${output}\\033[0m"
|
||||
cd "${output}"
|
||||
else
|
||||
echo "autojump: directory '${@}' not found"
|
||||
echo "\n${output}\n"
|
||||
echo "Try \`autojump --help\` for more information."
|
||||
false
|
||||
fi
|
||||
@ -78,17 +81,17 @@ jo() {
|
||||
fi
|
||||
|
||||
setopt localoptions noautonamedirs
|
||||
local new_path="$(autojump ${@})"
|
||||
if [[ -d "${new_path}" ]]; then
|
||||
local output="$(autojump ${@})"
|
||||
if [[ -d "${output}" ]]; then
|
||||
case ${OSTYPE} in
|
||||
linux-gnu)
|
||||
xdg-open "${new_path}"
|
||||
xdg-open "${output}"
|
||||
;;
|
||||
darwin*)
|
||||
open "${new_path}"
|
||||
open "${output}"
|
||||
;;
|
||||
cygwin)
|
||||
cygstart "" $(cygpath -w -a ${new_path})
|
||||
cygstart "" $(cygpath -w -a ${output})
|
||||
;;
|
||||
*)
|
||||
echo "Unknown operating system." 1>&2
|
||||
@ -96,6 +99,7 @@ jo() {
|
||||
esac
|
||||
else
|
||||
echo "autojump: directory '${@}' not found"
|
||||
echo "\n${output}\n"
|
||||
echo "Try \`autojump --help\` for more information."
|
||||
false
|
||||
fi
|
||||
|
@ -89,6 +89,10 @@ def in_bash():
|
||||
return 'bash' in os.getenv('SHELL')
|
||||
|
||||
|
||||
def is_autojump_sourced():
|
||||
return '1' == os.getenv('AUTOJUMP_SOURCED')
|
||||
|
||||
|
||||
def is_python2():
|
||||
return sys.version_info[0] == 2
|
||||
|
||||
|
@ -136,7 +136,7 @@ def parse_arguments(): # noqa
|
||||
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':
|
||||
print("\nPlease manually add %s to your user path" % bin_dir)
|
||||
else:
|
||||
@ -209,7 +209,7 @@ def main(args):
|
||||
if args.custom_install:
|
||||
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__":
|
||||
|
Loading…
Reference in New Issue
Block a user