README.md 4.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
# scd - smart change of directory

Define `scd` shell function for changing to any directory with
a few keystrokes.

`scd` keeps history of the visited directories, which serves as an index of
the known paths.  The directory index is updated after every `cd` command in
the shell and can be also filled manually by running `scd -a`.  To switch to
some directory, `scd` needs few fragments of the desired path to match with
the index.  A selection menu is displayed in case of several matches, with a
preference given to recently visited paths.  `scd` can create permanent
directory aliases, which appear as named directories in zsh session.

14
## INSTALLATION NOTES
15

16
Besides oh-my-zsh, `scd` can be used with *bash*, *dash* or *tcsh*
Pavol Juhas's avatar
Pavol Juhas committed
17
18
19
shells and is also available as Vim plugin
[scd.vim](https://github.com/pavoljuhas/scd.vim) and
[IPython](https://ipython.org) extension.  For installation details, see
20
21
22
23
24
25
26
27
https://github.com/pavoljuhas/smart-change-directory.

## SYNOPSIS

```sh
scd [options] [pattern1 pattern2 ...]
```

Pavol Juhas's avatar
Pavol Juhas committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## PATTERNS

Patterns may use all zsh [glob operators](
http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators)
available with *extendedglob* option.  Specified patterns must match
the absolute path and at least one of them must match in the tail.
Several special patterns are also recognized as follows:

<dl><dt>
^PAT</dt><dd>
  PAT must match at the beginning of the path, for example, "^/home"</dd><dt>
PAT$</dt><dd>
  require PAT to match the end of the path, "man$"</dd><dt>
./</dt><dd>
  match only subdirectories of the current directory</dd><dt>
:PAT</dt><dd>
  require PAT to match over the tail component, ":doc", ":re/doc"</dd>
</dl>


48
49
50
51
## OPTIONS

<dl><dt>
-a, --add</dt><dd>
Pavol Juhas's avatar
Pavol Juhas committed
52
  add current or specified directories to the directory index.</dd><dt>
53
54

--unindex</dt><dd>
55
  remove current or specified directories from the index.</dd><dt>
56
57
58
59
60
61
62
63
64
65

-r, --recursive</dt><dd>
  apply options <em>--add</em> or <em>--unindex</em> recursively.</dd><dt>

--alias=ALIAS</dt><dd>
  create alias for the current or specified directory and save it to
  <em>~/.scdalias.zsh</em>.</dd><dt>

--unalias</dt><dd>
  remove ALIAS definition for the current or specified directory from
Pavol Juhas's avatar
Pavol Juhas committed
66
67
  <em>~/.scdalias.zsh</em>.  Use "OLD" to purge aliases to non-existent
  directories.</dd><dt>
68

69
-A, --all</dt><dd>
Pavol Juhas's avatar
Pavol Juhas committed
70
71
72
73
74
75
  display all directories even those excluded by patterns in
  <em>~/.scdignore</em>.  Disregard the unique matching for a
  directory alias and filtering of less likely paths.</dd><dt>

-p, --push</dt><dd>
  use "pushd" to change to the target directory.</dd><dt>
76

77
78
79
80
81
82
83
84
85
86
--list</dt><dd>
  show matching directories and exit.</dd><dt>

-v, --verbose</dt><dd>
  display directory rank in the selection menu.</dd><dt>

-h, --help</dt><dd>
  display this options summary and exit.</dd>
</dl>

Pavol Juhas's avatar
Pavol Juhas committed
87

88
89
90
91
92
93
94
95
96
97
98
99
100
## Examples

```sh
# Index recursively some paths for the very first run
scd -ar ~/Documents/

# Change to a directory path matching "doc"
scd doc

# Change to a path matching all of "a", "b" and "c"
scd a b c

# Change to a directory path that ends with "ts"
101
scd "ts$"
102
103
104
105
106
107
108
109
110
111
112

# Show selection menu and ranking of 20 most likely directories
scd -v

# Alias current directory as "xray"
scd --alias=xray

# Jump to a previously defined aliased directory
scd xray
```

Pavol Juhas's avatar
Pavol Juhas committed
113
## FILES
114
115
116
117
118
119

<dl><dt>
~/.scdhistory</dt><dd>
    time-stamped index of visited directories.</dd><dt>

~/.scdalias.zsh</dt><dd>
Pavol Juhas's avatar
Pavol Juhas committed
120
121
122
123
124
125
126
127
128
    scd-generated definitions of directory aliases.</dd><dt>

~/.scdignore</dt><dd>
    <a href="http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators">
    glob patterns</a> for paths to be ignored in the scd search, for example,
    <code>/mnt/backup/*</code>.  The patterns are specified one per line
    and are matched assuming the <em>extendedglob</em> zsh option.  Lines
    starting with "#" are skipped as comments.  The .scdignore patterns
    are not applied in the <em>--all</em> mode.</dd>
129
130
</dl>

Pavol Juhas's avatar
Pavol Juhas committed
131
132

## ENVIRONMENT
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

<dl><dt>
SCD_HISTFILE</dt><dd>
    path to the scd index file (by default ~/.scdhistory).</dd><dt>

SCD_HISTSIZE</dt><dd>
    maximum number of entries in the index (5000).  Index is trimmed when it
    exceeds <em>SCD_HISTSIZE</em> by more than 20%.</dd><dt>

SCD_MENUSIZE</dt><dd>
    maximum number of items for directory selection menu (20).</dd><dt>

SCD_MEANLIFE</dt><dd>
    mean lifetime in seconds for exponential decay of directory
    likelihood (86400).</dd><dt>

SCD_THRESHOLD</dt><dd>
    threshold for cumulative directory likelihood.  Directories with
151
    a lower likelihood compared to the best match are excluded (0.005).
152
153
154
155
156
157
158
159
    </dd><dt>

SCD_SCRIPT</dt><dd>
    command script file where scd writes the final <code>cd</code>
    command.  This variable must be defined when scd runs in its own
    process rather than as a shell function.  It is up to the
    scd caller to use the output in <em>SCD_SCRIPT</em>.</dd>
</dl>