Permalink
Browse files

Merge branch 'os_x' into dada

* os_x:
  Squashed '.zsh.d/external/autojump/' changes from fd16ecb..a74ef31
  Let vim guess the background color.
  Tweaked zsh keybindings.
  • Loading branch information...
2 parents e291c70 + ea5ab96 commit 20478c3c4675b393c7f4f62264f51897e325dece @sudish committed Mar 3, 2012
View
@@ -7,7 +7,7 @@ if has("syntax")
syntax enable
endif
-set background=light
+"set background=light
set t_Co=256
"let g:solarized_termcolors=16
colorscheme solarized
@@ -73,48 +73,35 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with autojump. If not, see <http://www.gnu.org/licenses/>.
+Requirements
+============
+
+Python v2.6+ or 3.0+
+
Installation
============
Auto Installation
-----------------
-run::
-
- ./install.sh
-
-or::
-
- ./install.zsh
+run::
-depending on your shell.
-Enter your root password if it asks.
+ ./install.sh [ --local ] [ --zsh ]
-Add the line::
+and follow on screen instructions.
- source /etc/profile
+Use --local to install into current user's home directory.
-to ``~/.bashrc`` or ``~/.zshrc`` if it isn't already there.
+Use --zsh to install for Z shell.
Troubleshoot
------------
If the script fails, you may need to do::
- chmod +x install.(z)sh
-
-before the first step.
-
-
-Manual installation of autojump is very simple: copy
-
-- autojump to /usr/bin,
-- autojump.sh to /etc/profile.d,
-- autojump.1 to /usr/share/man/man1.
+ chmod +x install.sh
-Make sure to source ``/etc/profile`` in your ``.bashrc`` or ``.zshrc`` ::
-
- source /etc/profile
+before the first step.
Packaging
=========
@@ -126,7 +113,7 @@ For now gcarrier and I have packaged autojump for Arch Linux. It is available in
Autojump is now officially a part of Debian Sid, thanks to Tanguy Ortolo’s work (for policy reasons, it requires manual activation after installing, see /usr/share/doc/autojump/README.Debian). To install, type::
apt-get install autojump
-
+
Autojump is also available on the OSX Homebrew package manager::
brew install autojump
@@ -136,24 +123,10 @@ Autojump is also packaged for a number of other distros. Check the wiki for an u
Uninstallation
==============
-To completely remove autojump you should remove these files:
-
-``/etc/profile.d/autojump.bash``
-
-``/etc/profile.d/autojump.sh``
-
-``/etc/profile.d/autojump.zsh``
-
-``/usr/bin/autojump``
-
-``/usr/bin/jumpapplet``
-
-``/usr/share/autojump/icon.png``
-
-``/usr/share/autojump/``
+run::
-``/usr/share/man/man1/autojump.1``
+ ./uninstall.sh
-Remove any mention of autojump in your ``.bashrc`` or ``.zshrc``, then in currently running shells do:``source /etc/profile``.
+and follow on screen instructions.
If you keep getting ``autojump: command not found`` at the Bash prompt, do:``unset PROMPT_COMMAND``. You can also restart your shell.
@@ -85,15 +85,23 @@ def save(path_dict, dic_file):
for path,weight in sorted(path_dict.items(),key=itemgetter(1),reverse=True):
# the db is stored in utf-8
temp.write((unico("%s\t%s\n")%(weight,path)).encode("utf-8"))
- #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
- temp.flush()
- os.fsync(temp)
- temp.close()
+
+ # Catching disk errors and skipping save since file handle can't be closed.
+ try:
+ #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
+ temp.flush()
+ os.fsync(temp)
+ temp.close()
+ except IOError as ex:
+ print("Error while saving autojump database (disk full?)" %
+ ex, file=stderr)
+ return
+
# Use shutil.move instead of os.rename because windows doesn't support
# using rename to overwrite files
shutil.move(temp.name, dic_file)
try: #backup file
- import time
+ import time
if (not os.path.exists(dic_file+".bak") or
time.time()-os.path.getmtime(dic_file+".bak")>86400):
shutil.copy(dic_file, dic_file+".bak")
@@ -147,14 +155,14 @@ def open_dic(dic_file, error_recovery=False):
def forget(path_dict, dic_file):
"""Gradually forget about directories. Only call
from the actual jump since it can take time"""
- keyweight = sum(path_dict.values())
- if keyweight > MAX_KEYWEIGHT:
+ keyweight = sum(path_dict.values())
+ if keyweight > MAX_KEYWEIGHT:
for k in path_dict.keys():
path_dict[k] *= 0.9 * MAX_KEYWEIGHT / keyweight
save(path_dict, dic_file)
def clean_dict(sorted_dirs, path_dict):
- """Limits the sized of the path_dict to MAX_STORED_PATHS.
+ """Limits the sized of the path_dict to MAX_STORED_PATHS.
Returns True if keys were deleted"""
if len(sorted_dirs) > MAX_STORED_PATHS:
#remove 25 more than needed, to avoid doing it every time
@@ -183,7 +191,7 @@ def match(path, pattern, ignore_case=False, only_end=False):
return (does_match, eaten_path)
def find_matches(dirs, patterns, result_list, ignore_case, max_matches, current_dir):
- """Find max_matches paths that match the pattern,
+ """Find max_matches paths that match the pattern,
and add them to the result_list"""
for path, count in dirs:
# Don't jump to where we alread are
@@ -222,7 +230,7 @@ def shell_utility():
if ('-a', '') in optlist:
# The home dir can be reached quickly by "cd"
# and may interfere with other directories
- if(args[-1] != os.path.expanduser("~")):
+ if(args[-1] != os.path.expanduser("~")):
dicadd(path_dict, decode(args[-1]))
save(path_dict, dic_file)
elif ('--stat', '') in optlist:
@@ -241,7 +249,7 @@ def shell_utility():
import re
completion = False
#userchoice is i if the pattern is __pattern__i, otherwise -1
- userchoice = -1
+ userchoice = -1
results = []
if ('--completion', '') in optlist:
completion = True
@@ -286,10 +294,10 @@ def shell_utility():
find_matches(dirs, patterns, results, False, max_matches, current_dir)
# If not found, try ignoring case.
# On completion always show all results
- if completion or not results:
+ if completion or not results:
find_matches(dirs, patterns, results,
ignore_case=True,
- max_matches=max_matches, current_dir=current_dir)
+ max_matches=max_matches, current_dir=current_dir)
# Keep the database to a reasonable size
if not completion and clean_dict(dirs, path_dict):
save(path_dict, dic_file)
@@ -298,7 +306,7 @@ def shell_utility():
else: quotes = ""
if userchoice != -1:
- if len(results) > userchoice-1 :
+ if len(results) > userchoice-1 :
output(unico("%s%s%s") % (quotes,results[userchoice-1],quotes))
elif len(results) > 1 and completion:
output("\n".join(("%s%s%d%s%s" % (patterns[-1],
@@ -15,7 +15,7 @@
#along with autojump. If not, see <http://www.gnu.org/licenses/>.
#This shell snippet sets the prompt command and the necessary aliases
-_autojump()
+_autojump()
{
local cur
cur=${COMP_WORDS[*]:1}
@@ -29,10 +29,9 @@ EOF
}
complete -F _autojump j
-_autojump_files()
+_autojump_files()
{
- if [[ ${COMP_WORDS[COMP_CWORD]} == *__* ]]
- then
+ if [[ ${COMP_WORDS[COMP_CWORD]} == *__* ]]; then
local cur
#cur=${COMP_WORDS[*]:1}
cur=${COMP_WORDS[COMP_CWORD]}
@@ -48,23 +47,32 @@ EOF
complete -o default -o bashdefault -F _autojump_files cp mv meld diff kdiff3
#determine the data directory according to the XDG Base Directory Specification
-if [ -n "$XDG_DATA_HOME" ]
-then
+if [ -n "$XDG_DATA_HOME" ]; then
export AUTOJUMP_DATA_DIR="$XDG_DATA_HOME/autojump"
else
export AUTOJUMP_DATA_DIR=~/.local/share/autojump
fi
-if [ ! -e "${AUTOJUMP_DATA_DIR}" ]
-then
+if [ ! -e "${AUTOJUMP_DATA_DIR}" ]; then
mkdir -p "${AUTOJUMP_DATA_DIR}"
mv ~/.autojump_py "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration
mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null
mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null
fi
+# set paths if necessary for local installations
+if [ -d ~/.autojump/ ]; then
+ export PATH=~/.autojump/bin:"${PATH}"
+fi
+
export AUTOJUMP_HOME=${HOME}
-AUTOJUMP='{ [[ "$AUTOJUMP_HOME" == "$HOME" ]] && (autojump -a "$(pwd -P)"&)>/dev/null 2>>"${AUTOJUMP_DATA_DIR}/.autojump_errors";} 2>/dev/null'
+if [ "${AUTOJUMP_KEEP_SYMLINKS}" == "1" ]
+then
+ _PWD_ARGS=""
+else
+ _PWD_ARGS="-P"
+fi
+AUTOJUMP='{ [[ "$AUTOJUMP_HOME" == "$HOME" ]] && (autojump -a "$(pwd ${_PWD_ARGS})"&)>/dev/null 2>>"${AUTOJUMP_DATA_DIR}/.autojump_errors";} 2>/dev/null'
case $PROMPT_COMMAND in
*autojump*) ;;
@@ -73,3 +81,4 @@ esac
alias jumpstat="autojump --stat"
function j { new_path="$(autojump $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path";else false; fi }
+
@@ -15,7 +15,15 @@
#You should have received a copy of the GNU General Public License
#along with autojump. If not, see <http://www.gnu.org/licenses/>.
if [ "$BASH_VERSION" ] && [ -n "$PS1" ] && echo $SHELLOPTS | grep -v posix >>/dev/null; then
- . /etc/profile.d/autojump.bash
+ if [ -f ~/.autojump/etc/profile.d/autojump.bash ]; then
+ source ~/.autojump/etc/profile.d/autojump.bash
+ elif [ -f /etc/profile.d/autojump.bash ]; then
+ source /etc/profile.d/autojump.bash
+ fi
elif [ "$ZSH_VERSION" ] && [ -n "$PS1" ]; then
- . /etc/profile.d/autojump.zsh
+ if [ -f ~/.autojump/etc/profile.d/autojump.zsh ]; then
+ source ~/.autojump/etc/profile.d/autojump.zsh
+ elif [ -f /etc/profile.d/autojump.zsh ]; then
+ source /etc/profile.d/autojump.zsh
+ fi
fi
@@ -14,24 +14,34 @@
#You should have received a copy of the GNU General Public License
#along with autojump. If not, see <http://www.gnu.org/licenses/>.
-#determine the data directory according to the XDG Base Directory Specification
-if [ -n "$XDG_DATA_HOME" ]
-then
+# determine the data directory according to the XDG Base Directory Specification
+if [ -n "$XDG_DATA_HOME" ]; then
export AUTOJUMP_DATA_DIR="$XDG_DATA_HOME/autojump"
else
export AUTOJUMP_DATA_DIR=~/.local/share/autojump
fi
-if [ ! -e "${AUTOJUMP_DATA_DIR}" ]
-then
+if [ ! -e "${AUTOJUMP_DATA_DIR}" ]; then
mkdir -p "${AUTOJUMP_DATA_DIR}"
mv ~/.autojump_py "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration
mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null
mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null
fi
+# set paths if necessary for local installations
+if [[ -d ~/.autojump/ ]]; then
+ path=(~/.autojump/bin $path)
+ fpath=(~/.autojump/functions/ $fpath)
+fi
+
function autojump_preexec() {
- { (autojump -a "$(pwd -P)"&)>/dev/null 2>>|${AUTOJUMP_DATA_DIR}/.autojump_errors ; } 2>/dev/null
+ 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
}
typeset -ga preexec_functions
Oops, something went wrong.

0 comments on commit 20478c3

Please sign in to comment.