b6012bc2c32a124183d7c5713edee4e2341e1d3f
- Author
- Pavol Juhas <pavol.juhas@gmail.com>
- Committer
- Pavol Juhas <pavol.juhas@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/scd/README.md b/plugins/scd/README.md
2index 197cea50a45df926f924e10c8cd6647d50b7a5e0..86ab6720329f1faa13bb1aeab28d051c10b42bf2 100644
3--- a/plugins/scd/README.md
4+++ b/plugins/scd/README.md
5@@ -11,12 +11,9 @@ the index. A selection menu is displayed in case of several matches, with a
6 preference given to recently visited paths. `scd` can create permanent
7 directory aliases, which appear as named directories in zsh session.
8
9-## INSTALLATION
10+## INSTALLATION NOTES
11
12-For oh-my-zsh, add `scd` to the `plugins` array in the ~/.zshrc file as in the
13-[template file](../../templates/zshrc.zsh-template#L45).
14-
15-Besides zsh, `scd` can be used with *bash*, *dash* or *tcsh*
16+Besides oh-my-zsh, `scd` can be used with *bash*, *dash* or *tcsh*
17 shells and is also available as [Vim](http://www.vim.org/) plugin and
18 [IPython](http://ipython.org/) extension. For installation details, see
19 https://github.com/pavoljuhas/smart-change-directory.
20@@ -34,7 +31,7 @@ scd [options] [pattern1 pattern2 ...]
21 add specified directories to the directory index.</dd><dt>
22
23 --unindex</dt><dd>
24- remove specified directories from the index.</dd><dt>
25+ remove current or specified directories from the index.</dd><dt>
26
27 -r, --recursive</dt><dd>
28 apply options <em>--add</em> or <em>--unindex</em> recursively.</dd><dt>
29@@ -47,6 +44,10 @@ scd [options] [pattern1 pattern2 ...]
30 remove ALIAS definition for the current or specified directory from
31 <em>~/.scdalias.zsh</em>.</dd><dt>
32
33+-A, --all</dt><dd>
34+ include all matching directories. Disregard matching by directory
35+ alias and filtering of less likely paths.</dd><dt>
36+
37 --list</dt><dd>
38 show matching directories and exit.</dd><dt>
39
40@@ -70,7 +71,7 @@ scd doc
41 scd a b c
42
43 # Change to a directory path that ends with "ts"
44-scd "ts(#e)"
45+scd "ts$"
46
47 # Show selection menu and ranking of 20 most likely directories
48 scd -v
49diff --git a/plugins/scd/scd b/plugins/scd/scd
50index 1567d2736cf8f4fb9582dc35dfc97b2bace9d0c9..39b28237d11809cbd8f81c4a86bbdc85260903fa 100755
51--- a/plugins/scd/scd
52+++ b/plugins/scd/scd
53@@ -11,20 +11,22 @@ fi
54 local DOC='scd -- smart change to a recently used directory
55 usage: scd [options] [pattern1 pattern2 ...]
56 Go to a directory path that contains all fixed string patterns. Prefer
57-recently visited directories and directories with patterns in their tail
58-component. Display a selection menu in case of multiple matches.
59+recent or frequently visited directories as found in the directory index.
60+Display a selection menu in case of multiple matches.
61
62 Options:
63- -a, --add add specified directories to the directory index
64- --unindex remove specified directories from the index
65- -r, --recursive apply options --add or --unindex recursively
66+ -a, --add add specified directories to the directory index.
67+ --unindex remove current or specified directories from the index.
68+ -r, --recursive apply options --add or --unindex recursively.
69 --alias=ALIAS create alias for the current or specified directory and
70- store it in ~/.scdalias.zsh
71+ store it in ~/.scdalias.zsh.
72 --unalias remove ALIAS definition for the current or specified
73- directory from ~/.scdalias.zsh
74- --list show matching directories and exit
75- -v, --verbose display directory rank in the selection menu
76- -h, --help display this message and exit
77+ directory from ~/.scdalias.zsh.
78+ -A, --all include all matching directories. Disregard matching by
79+ directory alias and filtering of less likely paths.
80+ --list show matching directories and exit.
81+ -v, --verbose display directory rank in the selection menu.
82+ -h, --help display this message and exit.
83 '
84
85 local SCD_HISTFILE=${SCD_HISTFILE:-${HOME}/.scdhistory}
86@@ -35,9 +37,9 @@ local SCD_THRESHOLD=${SCD_THRESHOLD:-0.005}
87 local SCD_SCRIPT=${RUNNING_AS_COMMAND:+$SCD_SCRIPT}
88 local SCD_ALIAS=~/.scdalias.zsh
89
90-local ICASE a d m p i tdir maxrank threshold
91+local ICASE a d m p i maxrank threshold
92 local opt_help opt_add opt_unindex opt_recursive opt_verbose
93-local opt_alias opt_unalias opt_list
94+local opt_alias opt_unalias opt_all opt_list
95 local -A drank dalias
96 local dmatching
97 local last_directory
98@@ -56,7 +58,8 @@ zmodload -i zsh/zutil
99 zmodload -i zsh/datetime
100 zparseopts -D -- a=opt_add -add=opt_add -unindex=opt_unindex \
101 r=opt_recursive -recursive=opt_recursive \
102- -alias:=opt_alias -unalias=opt_unalias -list=opt_list \
103+ -alias:=opt_alias -unalias=opt_unalias \
104+ A=opt_all -all=opt_all -list=opt_list \
105 v=opt_verbose -verbose=opt_verbose h=opt_help -help=opt_help \
106 || $EXIT $?
107
108@@ -68,6 +71,11 @@ fi
109 # load directory aliases if they exist
110 [[ -r $SCD_ALIAS ]] && source $SCD_ALIAS
111
112+# Private internal functions are prefixed with _scd_Y19oug_.
113+# Clean them up when the scd function returns.
114+setopt localtraps
115+trap 'unfunction -m "_scd_Y19oug_*"' EXIT
116+
117 # works faster than the (:a) modifier and is compatible with zsh 4.2.6
118 _scd_Y19oug_abspath() {
119 set -A $1 ${(ps:\0:)"$(
120@@ -123,11 +131,52 @@ if [[ -n $opt_unalias ]]; then
121 $EXIT $?
122 fi
123
124+# The "compress" function collapses repeated directories to
125+# one entry with a time stamp that gives equivalent-probability.
126+_scd_Y19oug_compress() {
127+ awk -v epochseconds=$EPOCHSECONDS -v meanlife=$SCD_MEANLIFE '
128+ BEGIN { FS = "[:;]"; }
129+ length($0) < 4096 && $2 > 0 {
130+ tau = 1.0 * ($2 - epochseconds) / meanlife;
131+ if (tau < -6.9078) tau = -6.9078;
132+ prob = exp(tau);
133+ sub(/^[^;]*;/, "");
134+ if (NF) {
135+ dlist[last[$0]] = "";
136+ dlist[NR] = $0;
137+ last[$0] = NR;
138+ ptot[$0] += prob;
139+ }
140+ }
141+ END {
142+ for (i = 1; i <= NR; ++i) {
143+ d = dlist[i];
144+ if (d) {
145+ ts = log(ptot[d]) * meanlife + epochseconds;
146+ printf(": %.0f:0;%s\n", ts, d);
147+ }
148+ }
149+ }
150+ ' $*
151+}
152+