Autojump2

Autojump2 Git Source Tree

Root/autojump2.bash

1# Copyright Grégory Soutadé 2012
2
3# This file is part of autojump2
4
5# autojump2 is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# autojump2 is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with autojump2. If not, see <http://www.gnu.org/licenses/>.
17
18# Original code has been written by Joel Schaerer (https://github.com/joelthelion/autojump)
19
20_autojump()
21{
22 # No arguments or begining of a local directory --> directory completion
23 [ $COMP_CWORD -eq 0 ] && return
24 for i in ${COMP_WORDS[$COMP_CWORD]}* ; do
25[ -d "$i" ] && return
26 done
27
28 local cur
29 cur=${COMP_WORDS[*]:1}
30 while read i
31 do
32 COMPREPLY=("${COMPREPLY[@]}" "${i}")
33 done < <(autojump2 --bash --completion $cur)
34}
35
36complete -o dirnames -F _autojump cd
37complete -F _autojump autojump2
38
39function j {
40 new_path=""
41
42 # No args, goto home
43 if [ $# -eq 0 ] ; then
44\cd >/dev/null || return
45new_path="$(pwd -P)"
46 else
47case "$1" in
48# Handle relative paths
49 "-"|"\.\.*"|"/*"|"~.*")
50\cd "$1" && new_path="$(pwd -P)" || return
51;;
52 *)
53if [ ! -d "$1" ] ; then
54 new_path="$(autojump2 $@)"
55 if [ -n "$new_path" ]; then
56\cd "$new_path" || return
57echo -e "\\033[31m${new_path}\\033[0m"
58return
59 fi
60fi
61;;
62 esac
63 fi
64
65 # Classic cd behaviour
66 if [ -z "$new_path" -a -d "$1" ] ; then
67\cd "$1" || return
68 fi
69}

Archive Download this file

Branches