cdhist 4.0__tar.gz → 4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  README.html
2
+ Session.vim
2
3
  build/
3
4
  dist/
4
5
  .vscode/
cdhist-4.2/Makefile ADDED
@@ -0,0 +1,24 @@
1
+ NAME = $(shell basename $(CURDIR))
2
+ PYFILES = $(wildcard $(NAME)/*.py)
3
+
4
+ check:
5
+ ruff check $(PYFILES)
6
+ mypy $(PYFILES)
7
+ pyright $(PYFILES)
8
+ vermin -vv --no-tips -i $(PYFILES)
9
+
10
+ build:
11
+ rm -rf dist
12
+ python3 -m build --sdist --wheel
13
+
14
+ upload: build
15
+ twine3 upload dist/*
16
+
17
+ doc:
18
+ update-readme-usage
19
+
20
+ format:
21
+ ruff check --select I --fix $(PYFILES) && ruff format $(PYFILES)
22
+
23
+ clean:
24
+ @rm -vrf *.egg-info .venv/ build/ dist/ __pycache__ */__pycache__
cdhist-4.2/PKG-INFO ADDED
@@ -0,0 +1,417 @@
1
+ Metadata-Version: 2.2
2
+ Name: cdhist
3
+ Version: 4.2
4
+ Summary: Program to provide a Linux cd history directory stack
5
+ Author-email: Mark Blakeney <mark.blakeney@bullet-systems.net>
6
+ License: GPLv3
7
+ Project-URL: Homepage, https://github.com/bulletmark/cdhist
8
+ Keywords: bash,zsh,cd,fzf,git,worktree
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+
13
+ ## CDHIST - Linux Directory History
14
+ [![PyPi](https://img.shields.io/pypi/v/cdhist)](https://pypi.org/project/cdhist/)
15
+ [![AUR](https://img.shields.io/aur/version/cdhist)](https://aur.archlinux.org/packages/cdhist/)
16
+
17
+ [cdhist](http://github.com/bulletmark/cdhist) is a utility which provides a
18
+ Linux shell **cd history** directory stack. A shell `cd` wrapper function calls
19
+ cdhist to intercept your typed `cd` command and maintain an ordered stack of
20
+ all directories you have previously visited which can be listed and quickly
21
+ navigated to.
22
+
23
+ [cdhist](http://github.com/bulletmark/cdhist) can also be used with a fuzzy
24
+ finder (such as [`fzf`][fzf]) to fuzzy search and select on previously visited
25
+ directories, and can be used to easily `cd` between [`git
26
+ worktree`](https://git-scm.com/docs/git-worktree) directories. See the sections
27
+ below about [Fuzzy Finder Integration](#fuzzy-finder-integration) and [Git
28
+ Worktree Integration](#git-worktree-integration).
29
+
30
+ The latest version and documentation is available at
31
+ http://github.com/bulletmark/cdhist.
32
+
33
+ ## Example Usage
34
+
35
+ Use the `cd` command to change directory as normal:
36
+
37
+ ```sh
38
+ $ cd /tmp
39
+ $ cd /etc
40
+ $ cd /usr/share/doc
41
+ $ cd /boot/loader
42
+ $ cd ~/etc
43
+ $ cd
44
+ ```
45
+
46
+ At any point you can use the `cd --` command to list all your previously
47
+ visited directories and be prompted for one to select and `cd` to:
48
+
49
+ ```
50
+ $ cd --
51
+ 6 ...
52
+ 5 /tmp
53
+ 4 /etc
54
+ 3 /usr/share/doc
55
+ 2 /boot/loader
56
+ 1 ~/etc
57
+ 0 ~
58
+ Select index [or <enter> to quit]: 3
59
+ $ pwd
60
+ /usr/share/doc
61
+ ```
62
+
63
+ That's it! The above is all you really need to know. Instead of having to type
64
+ the directory name you merely enter it's index. The directories are displayed
65
+ most recently visited last, without duplicates. Index 0 is the current
66
+ directory, index 1 is the previous, index 2 is the second previous, up to a
67
+ user configurable number (default 200).
68
+
69
+ If you prefer a more modern approach you can use a fuzzy finder such as
70
+ [`fzf`][fzf], [`sk`][skim], [`tv`][television], or [`fzy`][fzy]
71
+ to show and select from the list, instead of a simple index prompt. See the
72
+ section on [Fuzzy Finder Integration](#fuzzy-finder-integration) below.
73
+
74
+ Other available commands and options are:
75
+
76
+ List the current stack and its indices (without prompting):
77
+
78
+ ```sh
79
+ $ cd -l
80
+ ```
81
+
82
+ Change immediately to directory corresponding to stack index 4:
83
+
84
+ ```sh
85
+ $ cd -4
86
+ ```
87
+
88
+ Search back through stack for directory containing "string" and `cd`
89
+ there:
90
+
91
+ ```sh
92
+ $ cd -/string
93
+ ```
94
+
95
+ Note, you can also type `string` at the `cd --` prompt to search.
96
+
97
+ Show help/usage:
98
+
99
+ ```sh
100
+ $ cd -h
101
+ ```
102
+
103
+ ## Installation
104
+
105
+ Arch users can install [cdhist from the
106
+ AUR](https://aur.archlinux.org/packages/cdhist/) and skip to the next section.
107
+
108
+ Python 3.8 or later is required. Note [cdhist is on
109
+ PyPI](https://pypi.org/project/cdhist/) so the easiest way to install it is to
110
+ use [`uv tool`][uvtool] (or [`pipx`][pipx] or [`pipxu`][pipxu]).
111
+
112
+ ```sh
113
+ $ uv tool install cdhist
114
+ ```
115
+
116
+ To upgrade:
117
+
118
+ ```sh
119
+ $ uv tool upgrade cdhist
120
+ ```
121
+
122
+ To uninstall:
123
+
124
+ ```sh
125
+ $ uv tool uninstall cdhist
126
+ ```
127
+
128
+ ## Setup
129
+
130
+ A user who wants to use the cdhist facility should add the following line to
131
+ their `~/.bashrc` or `~/.zshrc` file. Ensure it is added after where your PATH
132
+ is set up so that the command `cdhist` can be found. This creates the `cd`
133
+ wrapper command in your interactive shell session as a tiny function.
134
+
135
+ ```sh
136
+ source <(cdhist -i)
137
+ ```
138
+
139
+ Then log out and back in again to activate the new `cd` function. Note assuming
140
+ a normal `.bashrc` environment, this will alias your `cd` command in your
141
+ interactive terminal session only. The remapped `cd` will not be invoked by any
142
+ programs or scripts you run, or for other users etc.
143
+
144
+ ### Alternative Command Name
145
+
146
+ Some people may prefer not to alias their real `cd` command to this utility and
147
+ just use an alternative unique command name. To do this, simply add your
148
+ desired command name as the first argument to the `cdhist -i` option in your
149
+ shell initialization code. E.g, to use the command name `xd` rather than `cd`,
150
+ use the following in your `~/.bashrc` or `~/.zshrc` file:
151
+
152
+ ```sh
153
+ source <(cdhist -i xd)
154
+ ```
155
+
156
+ Then log out/in, and then use `xd /tmp` to change dir, `xd --` to see and
157
+ select directories, etc.
158
+
159
+ ### Default Options
160
+
161
+ You can set default cdhist options by appending options in the shell
162
+ initialization code, e.g:
163
+
164
+ ```sh
165
+ source <(cdhist -i "cd -arm 100")
166
+ ```
167
+
168
+ The above sets `-a (--purge-always)`, '' `-r (--git-relative)`, and `-m
169
+ (--size) 100` options as defaults for your `cd` command.
170
+
171
+ Note you can use multiple source lines to define multiple commands. E.g. define
172
+ one alias for your `cd` command, and another alias for your git worktree
173
+ command (e.g. `wt`). Both can have different cdhist options.
174
+
175
+ The following options are sensible candidates to set as default options:
176
+ `-m/--size`, `-a/--purge-always`, `-g/--git`, `-r/--git-relative`,
177
+ `-u/--no-user`, `-F/--fuzzy`, `-G/--no-fuzzy-git`.
178
+
179
+ Note if you set `-r/--git-relative` or `-u/--no-user` options as default then
180
+ options `-R/--no-git-relative` and `-U/--user` exist to allow you to
181
+ temporarily override those defaults via the command line.
182
+
183
+ ### Fuzzy Finder Integration
184
+
185
+ Any of the popular command line fuzzy search finders such as
186
+ [`fzf`][fzf], [`sk`][skim], [`tv`][television], or [`fzy`][fzy]
187
+ can be used with `cdhist`.
188
+
189
+ E.g. to use [`fzf`][fzf]:
190
+
191
+ ```sh
192
+ source <(cdhist -i "cd -F fzf")
193
+ ```
194
+
195
+ Or, to use [`television`][television]:
196
+
197
+ ```sh
198
+ source <(cdhist -i "cd -F \"tv --no-preview\"")
199
+ ```
200
+
201
+ Now when you type `cd --` you will be prompted with a list of directories via
202
+ your fuzzy finder so you can search for a directory to select by fuzzy text
203
+ matching.
204
+
205
+ In the following description, [`fzf`][fzf] will be used as it is by far the
206
+ most popular fuzzy finder and the one used by the author. When you set up `fzf`
207
+ [shell integration](https://junegunn.github.io/fzf/shell-integration/) then you
208
+ can use the following terminal key bindings for `fzf`:
209
+
210
+ - `CTRL+t` to select files,
211
+ - `CTRL+r` to select commands,
212
+ - `ATL+c` to select directories.
213
+
214
+ However, I never use the last `ATL+c` function because it lists directories
215
+ only under the current directory whereas I am much more interested in listing
216
+ all directories I have previously visited, i.e. those maintained by cdhist. So
217
+ I disable that function in `fzf` by setting the `FZF_ALT_C_COMMAND` to an empty
218
+ string before I source `fzf` in my `.bashrc` when [setting `fzf` up](https://junegunn.github.io/fzf/shell-integration/#setting-up-shell-integration).
219
+
220
+ Then I set the following shell key binding in my `~/.inputrc` file (need to
221
+ restart your shell to activate):
222
+
223
+ ```sh
224
+ "\ec": "cd --\n"
225
+ ```
226
+
227
+ Now pressing `ALT+c` invokes cdhist to bring up the `fzf` list of my previously
228
+ visited directories. Alternately, use `ALT+d` for cdhist and keep `ALT+c` for
229
+ the default `fzf` search behavior.
230
+
231
+ You also have the choice of keeping the standard `cd --` command to work with
232
+ simple index selection, and map a different cdhist command name to use with
233
+ `ALT+c` only for the fuzzy finder. To do this, add the following 2 lines to your
234
+ `~/.bashrc` or `~/.zshrc` file:
235
+
236
+ ```sh
237
+ source <(cdhist -i)
238
+ source <(cdhist -i "cdfuzzy -F fzf")
239
+ ```
240
+
241
+ And then in your `~/.inputrc`:
242
+
243
+ ```
244
+ "\ec": "cdfuzzy --\n"
245
+ ```
246
+
247
+ Note all the above assumes you have the fuzzy finder somewhere in your PATH. If
248
+ you don't then just specify the full path, e.g:
249
+
250
+ ```sh
251
+ source <(cdhist -i "cd -F /path-to/fzf")
252
+ ```
253
+
254
+ ### GIT Worktree Integration
255
+
256
+ [cdhist](http://github.com/bulletmark/cdhist) can be used to easily `cd`
257
+ between [git worktree](https://git-scm.com/docs/git-worktree)
258
+ directories. You use the `cd -g` command to list all your worktrees and
259
+ be prompted for one to select, and then you will be switched to the
260
+ associated directory, and it will be added to your `cd` history.
261
+
262
+ ```sh
263
+ # Current directory:
264
+ $ pwd
265
+ /home/mark/src/myprog
266
+
267
+ # List worktrees using standard git command:
268
+ $ git worktree list
269
+ /home/mark/src/myprog f76b8e0 [main]
270
+ /home/mark/src/development 9796714 [development]
271
+ /home/mark/src/milestone1 bc921b8 [milestone1]
272
+ /home/mark/src/test e6d965a [test]
273
+
274
+ # Alternately, use cdhist to list worktrees and choose one to navigate to:
275
+ $ cd -g
276
+ 3 ~/src/development 9796714 [development]
277
+ 2 ~/src/milestone1 bc921b8 [milestone1]
278
+ 1 ~/src/test e6d965a [test]
279
+ 0 ~/src/myprog f76b8e0 [main]
280
+ Select index [or <enter> to quit]: 2
281
+
282
+ $ pwd
283
+ /home/mark/src/milestone1
284
+
285
+ # Or, use cdhist to navigate to worktree dir for given branch name or
286
+ # commit:
287
+ $ cd -g main
288
+ $ pwd
289
+ /home/mark/src/myprog
290
+ ```
291
+
292
+ Instead of having to type the full git repository directory name you merely are
293
+ prompted with a list and enter it's index. Or just directly enter the branch
294
+ name (or commit hash). The directories are displayed in the same order as the
295
+ output of the `git worktree list` command, except that the git directory
296
+ corresponding to the current working directory is shown first (index 0)
297
+ consistent with how the current directory is shown at index 0 for normal cd
298
+ history and thus conveniently showing you which git worktree you are currently
299
+ in which `git worktree list` unfortunately does not show.
300
+
301
+ In you enter text instead of an index, you only need to enter as much of the
302
+ branch name, or commit hash, as needed to be unique. Note that `cd -g` nicely
303
+ presents paths based from your HOME directory with a tilde (`~`) unlike the
304
+ longer full path displayed by `git worktree list` (although you can disable
305
+ that with the `-u/--no-user` option, likely set as a [default
306
+ option](#default-options)).
307
+
308
+ Note if you have `-F/--fuzzy` enabled but you don't want to also use that for
309
+ git worktree selection then you can disable it with the `-G/--no-fuzzy-git`
310
+ option.
311
+
312
+ #### Relative Git Worktree Directories
313
+
314
+ The `git worktree list` command displays absolute directory paths, and cdhist
315
+ does also by default, but many users prefer them displayed as shorter relative
316
+ paths. The Git worktree command does not provide this but you can enable it in
317
+ cdhist by adding the `-r/--git-relative` option, e.g:
318
+
319
+ ```sh
320
+ $ cd -gr
321
+ 3 ../development 9796714 [development]
322
+ 2 ../milestone1 bc921b8 [milestone1]
323
+ 1 ../test e6d965a [test]
324
+ 0 . f76b8e0 [main]
325
+ Select index [or <enter> to quit]:
326
+ ```
327
+
328
+ Most likely you will want to set this as your default so do that by adding
329
+ `-r/--git-relative` as a [default option](#default-options).
330
+
331
+ #### Git Worktree Functionality Alone
332
+
333
+ Some users may want the git worktree functionality provided by cdhist but are
334
+ not interested in the standard `cd` history functionality, or alternately, want
335
+ to use a completely separate command for the git worktree functionality. To do
336
+ this, simply add your desired command name and the git option the first
337
+ argument to the `cdhist` command in your shell initialization code. E.g, to use
338
+ the command name `wt` for git worktree functionality (only), add the following
339
+ in your `~/.bashrc` or `~/.zshrc` file:
340
+
341
+ ```sh
342
+ source <(cdhist -i "wt -g")
343
+ ```
344
+
345
+ Then log out/in. Type `wt` to list the git worktrees and be prompted to select
346
+ the directory etc. Of course, you can define this `wt` command in parallel to
347
+ using cdhist for your `cd` command if you want.
348
+
349
+ ## Command Line Usage
350
+
351
+ Type `cdhist -h` to view the usage summary:
352
+
353
+ ```
354
+ usage: cdhist [-h] [-i] [-l] [-m SIZE] [-n NUM_LINES] [-p] [-a] [-g] [-r]
355
+ [-R] [-u] [-U] [-F FUZZY] [-G] [-L] [-P] [-V]
356
+ [directory]
357
+
358
+ A Linux shell directory stack "cd history" function.
359
+
360
+ positional arguments:
361
+ directory directory (or branch for git worktree) to cd to, or
362
+ "--" to list history and prompt, or "-n" for n'th
363
+ entry in list or "-/<string>" to match for "string" in
364
+ dir
365
+
366
+ options:
367
+ -h, --help show help/usage
368
+ -i, --init output shell initialization code. Optionally specify
369
+ alternative command name as argument, default="cd"
370
+ -l, --list just list directory history
371
+ -m, --size SIZE maximum size of directory history (default=200)
372
+ -n, --num-lines NUM_LINES
373
+ limit output to specified number of lines
374
+ -p, --purge just purge non-existent directories from history
375
+ -a, --purge-always always purge non-existent directories every write
376
+ -g, --git show git worktree directories instead
377
+ -r, --git-relative show relative git worktree paths instead of absolute
378
+ -R, --no-git-relative
379
+ do not show relative git worktree paths (default)
380
+ -u, --no-user do not substitute "~" for home directory
381
+ -U, --user do substitute "~" for home directory (default)
382
+ -F, --fuzzy FUZZY use specified fuzzy finder program to select directory
383
+ from list
384
+ -G, --no-fuzzy-git do not use fuzzy finder for git worktree selection
385
+ -L, --follow-links follow symbolic links (default=true)
386
+ -P, --follow-physical
387
+ follow links to physical directory
388
+ -V, --version just output cdhist version
389
+ ```
390
+
391
+ ## Limitations
392
+
393
+ Regular `cd`, e.g. as provided by the bash builtin, offers some esoteric
394
+ command line options such as `-e` and `-@`, and shell options such as `autocd`,
395
+ `cdspell`, `cdable_vars`. These rarely used options are not supported by
396
+ cdhist.
397
+
398
+ ## License
399
+
400
+ Copyright (C) 2010 Mark Blakeney. This program is distributed under the
401
+ terms of the GNU General Public License.
402
+ This program is free software: you can redistribute it and/or modify it
403
+ under the terms of the GNU General Public License as published by the
404
+ Free Software Foundation, either version 3 of the License, or any later
405
+ version.
406
+ This program is distributed in the hope that it will be useful, but
407
+ WITHOUT ANY WARRANTY; without even the implied warranty of
408
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
409
+ Public License at <http://www.gnu.org/licenses/> for more details.
410
+
411
+ [pipx]: https://github.com/pypa/pipx
412
+ [pipxu]: https://github.com/bulletmark/pipxu
413
+ [uvtool]: https://docs.astral.sh/uv/guides/tools/#installing-tools
414
+ [fzf]: https://github.com/junegunn/fzf
415
+ [fzy]: https://github.com/jhawthorn/fzy
416
+ [skim]: https://github.com/skim-rs/skim
417
+ [television]: https://github.com/alexpasmantier/television