• Stars
    star
    2,426
  • Rank 18,959 (Top 0.4 %)
  • Language
    Shell
  • Created about 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚀 A next-generation cd command with your interactive filter

enhan/cd

🚀 🚀 🚀

enhancd is an enhanced cd command integrated with a command line fuzzy finder based on UNIX concept.

Typing “cd” in your console, enhancd provides you a new window to visit a directory. The basic UX of enhancd is almost same as builtin cd command but totally differenent in that you can choose where to go from the list of visited directories in the past. You can select the directory you want to visit using your favorite command line interactive filter (e.g. fzf). It just extends original cd command but brings you completely new experience.

Getting Started

demo

Trying enhancd on the current shell, you need to run this command:

source ./init.sh

After that, cd is aliased to __enhancd::cd so you can use enhancd feature by typing cd as usual.

Using enhancd feature requires a command line fuzzy finder tool (as known as an interactive filter), for example, fzf. The ENHANCD_FILTER is the command name for interactive filters. It is a colon-separated list of executables. Each arguments can be also included to the list. It searches from the top of the list and uses the first installed one. A default value is fzy:fzf:peco:sk:zf.

Changing the order of each executables in the list, you can change the interactive filter command used by enhancd. Let’s configure what’s your favorite one!

$ export ENHANCD_FILTER="fzf --height 40%:fzy"

Usage

The usage of cd command powered by enhancd is almost same as built-in cd command.

$ cd [-|..|.] <dir>
Argument Behavior
(none) List all directories visited in the past. The HOME is always shown at a top of the list as builtin cd does.
<dir> (exists in cwd) Go to dir without the filter command (same as builtin cd)
<dir> (not exists in cwd) Find directories matched with dir or being similar to dir and then pass them to the filter command. A directory named "afx" is not in the current directory but enhancd cd can show where to go from the visited log.
- List latest 10 directories
.. List all parent directories of cwd
. List all sub directories in cwd

Hyphen (-)

List latest 10 directories. This is useful for choosing the directory recently visited only. The number of directories shown as the choices can be changed as you like by editing ENHANCD_HYPHEN_NUM (Defaults to 10).

$ cd -enhancd
  2/10
> /Users/babarot/src/github.com/b4b4r07/enhancd
  /Users/babarot/src/github.com/b4b4r07/enhancd/src

To disable this feature, set ENHANCD_ENABLE_HYPHEN to false.

Double-dot (..)

List all parent directories of the current working directory to quickly go back to any directory instead of typing cd ../../.. redundantly.

Let's say you're in ~/src/github.com/b4b4r07/enhancd. The result of cd .. will be:

$ cd .._
  6/6
> /Users/babarot/src/github.com/b4b4r07
  /Users/babarot/src/github.com
  /Users/babarot/src
  /Users/babarot
  /Users
  /

To disable this feature, set ENHANCD_ENABLE_DOUBLE_DOT to false.

Single-dot (.)

List all sub directories recursively located under the current directory. The built-in cd command does nothing even if a dot (.) is passed. Whereas, in enhancd cd, it's useful for visiting any sub directory easily (the example below is that if you're in "enhancd" directory):

$ cd ._
  8/8
> .github/
  .github/ISSUE_TEMPLATE/
  .github/workflows/
  conf.d/
  functions/
  functions/enhancd/
  functions/enhancd/lib/
  src/

This would be very useful to find a directory you want to visit within current directory. It uses find command internally to list directories but it would be good to install fd (sharkdp/fd) command. It'll be more fast and also be included hidden directories into the list if fd is used.

To disable this feature, set ENHANCD_ENABLE_SINGLE_DOT to false.

Piping

💡 Zsh only.

enhancd allows you to pass one or multiple directory paths to cd commands like this:

$ (paths) | cd
piping

Options

$ cd --help
Usage: cd [OPTIONS] [dir]

OPTIONS:
  -h, --help          Show help message
  -q                  (default) quiet, no output or use of hooks
  -s                  (default) refuse to use paths with symlinks
  -L                  (default) retain symbolic links ignoring CHASE_LINKS
  -P                  (default) resolve symbolic links as CHASE_LINKS

Version: 2.3.0

In enhancd, all options are defined at a configuration file (config.ltsv). This mechanism allows you to add what you want as new option or delete unneeded default options. It uses LTSV (Labeled Tab-Separated Values) format.

For example, let's say you want to use ghq list as custom inputs for cd command. In this case, all you have to do is just to add this one line to your any config.ltsv:

short:-G	long:--ghq	desc:Show ghq path	func:ghq list --full-path	condition:which ghq
Label Description
short (*) a short option (e.g. -G)
long (*) a long option (e.g. --ghq)
desc a description for the option
func (*) a command which returns directory list (e.g. ghq list --full-path)
condition a command which determine that the option should be implemented or not (e.g. which ghq)
format a string which indicates how to format a line selected by the filter before passing cd command. % is replaced as a selected line and then passed to cd command (e.g. $HOME/src/%). This is useful for the case that input sources for the interactive filter are not a full-path.

Note: *: A required key. But either short or long is good enough.

options

enhancd loads these config.ltsv files located in:

  1. $ENHANCD_ROOT/config.ltsv
  2. $ENHANCD_DIR/config.ltsv
  3. $HOME/.config/enhancd/config.ltsv

Thanks to this feature, it's easy to add your custom option as you hope.

Installation

Manual

enhancd is consists of a bunch of shell scripts. Running this command to clone repo and to run an entrypoint script enables you to try it out.

git clone https://github.com/b4b4r07/enhancd && source enhancd/init.sh

Using package manager

Using AFX for installing and managing shell plugins is heavily recommended now because it's better solution to manage enhancd and your favorite interactive filter at the same way.

github:
- name: b4b4r07/enhancd
  description: A next-generation cd command with your interactive filter
  owner: b4b4r07
  repo: enhancd
  plugin:
    env:
      ENHANCD_FILTER: >
        fzf --preview 'exa -al --tree --level 1 --group-directories-first --git-ignore
        --header --git --no-user --no-time --no-filesize --no-permissions {}'
        --preview-window right,50% --height 35% --reverse --ansi
        :fzy
        :peco
    sources:
    - init.sh
- name: junegunn/fzf
  description: A command-line fuzzy finder
  owner: junegunn
  repo: fzf
  command:
    build:
      steps:
        - ./install --bin --no-update-rc --no-key-bindings
    link:
    - from: 'bin/fzf'
    - from: 'bin/fzf-tmux'
  plugin:
    sources:
    - shell/completion.zsh
    env:
      FZF_DEFAULT_COMMAND: fd --type f
      FZF_DEFAULT_OPTS: >
        --height 75% --multi --reverse --margin=0,1
        --bind ctrl-f:page-down,ctrl-b:page-up,ctrl-/:toggle-preview
        --bind pgdn:preview-page-down,pgup:preview-page-up
        --marker="✚" --pointer="▶" --prompt="❯ "
        --no-separator --scrollbar="█"
        --color bg+:#262626,fg+:#dadada,hl:#f09479,hl+:#f09479
        --color border:#303030,info:#cfcfb0,header:#80a0ff,spinner:#36c692
        --color prompt:#87afff,pointer:#ff5189,marker:#f09479
      FZF_CTRL_T_COMMAND: rg --files --hidden --follow --glob "!.git/*"
      FZF_CTRL_T_OPTS: --preview "bat --color=always --style=header,grid --line-range :100 {}"
      FZF_ALT_C_COMMAND: fd --type d
      FZF_ALT_C_OPTS: --preview "tree -C {} | head -100"

then,

$ afx install

For more details, see the full documentation.

Other installations are here!
Case Installation

Fig

Install enhancd with Fig on zsh, bash, or fish with just one click.

Bash

  1. Run cloning on the console.

    $ git clone https://github.com/b4b4r07/enhancd.git /path/to/enhancd
  2. Add this line to your bashrc.

    # ~/.bashrc
    source /path/to/enhancd/init.sh
Zsh

zplug (powerful plugin manager for zsh):

Add this line to your zshrc

# .zshrc
zplug "b4b4r07/enhancd", use:init.sh

and then run this command.

$ zplug install

oh-my-zsh user:

Clone repo,

$ git clone https://github.com/b4b4r07/enhancd.git $ZSH_CUSTOM/plugins/enhancd

and then load as a plugin in your zshrc.

# .zshrc
plugins+=(enhancd)

Fish

System Requirements:

Install with Fisher:

$ fisher install b4b4r07/enhancd

Configuration

ENHANCD_DIR

A directory to have enhancd.log and config.ltsv. It defaults to ~/.enhancd.

ENHANCD_FILTER

A list of executable commands (interactive filter such as fzf) concatenated with ':' like PATH. For example:

export ENHANCD_FILTER="/usr/local/bin/sk:fzf --ansi:fzy:non-existing-filter"

The command found by searching in order from the first is used as an interactive filter of enhancd. If there is nothing any commands, it only provides a functionality as a built-in cd command.

ENHANCD_COMMAND

A command name to trigger enhancd cd command. It defaults to cd. By default, enhancd aliases cd to enhancd one. So you want to prevent it, you need to set this environemnt variable.

After set, you need to set restart your shell to apply the changes.

$ echo $ENHANCD_COMMAND
cd
$ export ENHANCD_COMMAND=ecd
$ source /path/to/init.sh
ENHANCD_ENABLE_DOUBLE_DOT

Enable to list parent directories when .. is given. Defaults to true.

ref: Double-dot (..)

ENHANCD_ENABLE_SINGLE_DOT

Enable to list sub directories in the current directory when . is given. Defaults to true.

ref: Single-dot (.)

Note Added in #188 #198

ENHANCD_ENABLE_HYPHEN

Enable to list visited directories limited latest 10 cases when - is given. Defaults to true.

ref: Single-dot (.)

ENHANCD_ENABLE_HOME

Enable to use the interactive filter when no argument is given. When set it to false, cd just changes the current working directory to home directory. Defaults to true.

ENHANCD_ARG_DOUBLE_DOT

You can customize the double-dot (..) argument for enhancd by this environment variable. Default is ...

If you set this variable any but .., it gives you the double-dot behavior with that argument; i.e. upward search of directory hierarchy. Then cd .. changes current directory to parent directory without interactive filter.

In other words, you can keep original cd .. behavior by this option.

ENHANCD_ARG_SINGLE_DOT

You can customize the single-dot (.) argument for enhancd by this environment variable. Default is ..

ENHANCD_ARG_HYPHEN

A string to trigger a hyphen behavior. Default is -.

If you set this variable any but -, it gives you a hyphen behavior with that argument; i.e. backward search of directory-change history. Then cd - changes current directory to $OLDPWD without interactive filter.

In other words, you can keep the original cd - behavior by setting this option.

ENHANCD_ARG_HOME

You can customize to trigger the argumentless cd behavior by giving the string specified by this environment variable as an argument. Default is empty string.

If you set this variable any but empty string, it gives you the behavior of cd with no argument; i.e. backward search of the whole directory-change history. Then cd with no argument changes current directory to $HOME without interactive filter.

In other words, you can keep original behavior of cd with no argument by setting this option.

ENHANCD_HYPHEN_NUM

A variable to specify how many lines to show up in the list when a hyphen behavior. Default is 10.

ENHANCD_HOOK_AFTER_CD

Default is empty. You can run any commands after changing directory with enhancd (e.g. set ls to this variable => same as cd && ls).

ENHANCD_USE_ABBREV

Set this to true to abbreviate the home directory prefix to ~ when performing an interactive search. Using the example shown previously, all entries when searching will be shown as follows:

false true
$ cd -_
  10/10
  /Users/babarot/src
> /Users/babarot/src/github.com/b4b4..
  /Users/babarot/enhancd
  /Users/babarot/src/github.com/b4b4..
  /Users/babarot/src/github.com/b4b4..
  /Users/babarot/src/github.com/b4b4..
  /Users/babarot/src/github.com/b4b4..
  /Users/babarot/.tmux/plugins/tmux-..
  /Users/babarot/.tmux/plugins/tmux-..
  /Users/babarot/.afx/github.com/b4b..
$ cd -_
  10/10
  ~/src
> ~/src/github.com/b4b4..
  ~/enhancd
  ~/src/github.com/b4b4..
  ~/src/github.com/b4b4..
  ~/src/github.com/b4b4..
  ~/src/github.com/b4b4..
  ~/.tmux/plugins/tmux-..
  ~/.tmux/plugins/tmux-..
  ~/.afx/github.com/b4b..

Default is false (disable).

Known issues

Enhancd complete (fish):

On fish shell, you can use alt+f to trigger enhancd when typing a command, the selected item will be appended to the commandline

  • Fish version
    • Because of how fish piping works, it's not possible to pipe to cd like : ls / | cd

References

Interactive filter commands

The "visual filter" (interactive filter) is what is called "Interactive Grep Tool" according to percol that is a pioneer in interactive selection to the traditional pipe concept on UNIX. Some candidates of an interactive filter are listed on here.

Name Stars Language Activity
junegunn/fzf
mooz/percol
peco/peco
jhawthorn/fzy
mattn/gof
garybernhardt/selecta
mptre/pick
lotabout/skim
natecraddock/zf

Versus

Similar projects.

(However, the basic concept of enhancd is totally different from these directory-jump tools)

License

MIT

More Repositories

1

dotfiles

A repository that gathered files starting with dot
Shell
759
star
2

emoji-cli

😱 Emoji completion on the command line
Shell
424
star
3

gomi

🗑️ Replacement for UNIX rm command!
Go
304
star
4

httpstat

It's like curl -v, with graphs and colors
Shell
254
star
5

afx

📦 Package manager for CLI
Go
146
star
6

gist

:octocat: A simple gist editor for CLI
Go
130
star
7

zsh-vimode-visual

Implement the vim-like visual mode to vi-mode of zsh
Shell
109
star
8

stein

A linter for config files with a customizable rule set
Go
97
star
9

zsh-history

A plugin for zsh history extended by golang, dealing it like SQL
Go
84
star
10

github-labeler

Declarative way to configure GitHub labels
Go
74
star
11

iap_curl

A CLI that is curl wrapper for making HTTP request to IAP-protected app, more easier than curl
Go
61
star
12

history

A CLI to provide enhanced history for your shell
Go
59
star
13

ssh-keyreg

A CLI tool add ssh key to github.com user account
Shell
54
star
14

git-bump

Bump version (git tag) to next one with semver.
Go
49
star
15

zsh-gomi

🚮 zsh-gomi implements CLI gomi written in Go.
Shell
32
star
16

brionac

🐉 A simple alternative means of the Brewfile
Go
28
star
17

zgencomp

A generator for Zsh completion function
Go
25
star
18

go-finder

CLI finder wrapper (fzf, peco, etc) for golang
Go
21
star
19

vim-sqlfmt

A plugin for SQL formatter like gofmt
Vim Script
18
star
20

manyawk

🐒 GNU AWK library
Awk
18
star
21

vim-shellutils

🐚 A simple UNIX Shell commands emulator that works within Vim
Vim Script
18
star
22

favdir

Save favorite directory on bash and zsh
Shell
16
star
23

go-pipe

Unix-like pipelines for Go
Go
15
star
24

cli-finder

📁 A command-line finder with fzf
Shell
14
star
25

ultimate

Ultimate is a simple theme for minimalistic zsh users
Shell
12
star
26

crowi-cli

A simple Crowi client for CLI
Go
12
star
27

cli

Get binaries from GitHub releases
Shell
12
star
28

gch

⚡ List the changes that are applied to the repository in the $GOPATH/src directory.
Go
11
star
29

yamato-bot

JavaScript
11
star
30

tellme.tokyo

🗼 @babarot's blog
CSS
11
star
31

vim-ansible-vault

Encrypt/Decrypt the file contents on the buffer from Vim command line with ansible-vault
Vim Script
11
star
32

zle-vimode

Shell
10
star
33

twistd

🐦 Twitter Streaming Daemon
Go
9
star
34

gotcha

gotcha is a simple tool that grabs Go packages
Go
9
star
35

action-changed-objects

GitHub Action to get changed files compared with origin/master
Shell
9
star
36

zgit

[WIP] zgit is simple git interface
Shell
9
star
37

http_code

http_code returns HTTP status code description
Shell
9
star
38

action-opa

Run opa test command with GitHub Actions
Shell
8
star
39

peco-tmux.sh

Run piping peco opening new tmux pane like fzf-tmux
Shell
8
star
40

copy

Shell
8
star
41

zspec

zspec is a testing framework for zsh
Shell
7
star
42

epoch-cat

Epoch time converter and filter like less
Go
7
star
43

easy-oneliner

Shell
7
star
44

pkill.sh

Kill processes by filtering tool
Shell
6
star
45

vtest

Unix `test` command for Version comparison
Go
6
star
46

bashmark

Directory bookmarks for the shell
Shell
6
star
47

cdhist

Cdhist adds 'web-browser like history' to your bash shell.
Shell
6
star
48

vim-sunset

Automatically set background on local sunrise/sunset time
Vim Script
6
star
49

kubeabc

A toolkit for k8s developers
Go
6
star
50

git-br

Shell
5
star
51

tmux-git-prompt

Git status on Tmux status line
Shell
5
star
52

vim-buftabs

A plugin for buffer like the tabpages in statusline
Vim Script
5
star
53

zsh-prompt-minimal

Super super minimal prompt for zsh
Shell
5
star
54

vim-crowi

A simple vim plugin for Crowi
Vim Script
5
star
55

zplug-cd

4
star
56

fzf-plugins

Plugins for fzf
Shell
4
star
57

vim-autocdls

🐾 A Vim plugin to run shell like ls command after :cd, :lcd and so on
Vim Script
4
star
58

misc

📥 Miscellaneous files which don't belong to any project
Shell
4
star
59

git-fzf

Shell
4
star
60

git-conflict

Shell
3
star
61

zsh-history-ltsv

🔍 Command history tool available on Zsh enhanced drastically
Shell
3
star
62

git-powertools

Shell
3
star
63

tmux-k8s-context-indicator

Shell
3
star
64

git-switch

Shell
3
star
65

ltsv.sh

A simple ltsv parser with extended awk
Shell
3
star
66

zplug-rm

3
star
67

action-conftest

Run conftest test command with GitHub Actions
Shell
3
star
68

github-comment

Post a text to GitHub issue / pull request
Go
3
star
69

release-go

Helper script for goreleaser to make it easy to release Go artifacts
Shell
3
star
70

tmux-powertools

Shell
3
star
71

git-ls

List file entries like GitHub file browser
Shell
3
star
72

vim-favdir

Save favorite directory on vim
Vim Script
3
star
73

releases

The easiest way which grabs binaries from GitHub Releases
Shell
3
star
74

gocli

Examples of CLI command implementation pattern for golang
Go
3
star
75

cursor-x.nvim

Lua
2
star
76

blog

A CLI tool for editing blog built by Hugo
Go
2
star
77

neoplug.vim

Manage Vim plugins by neobundle but install them with vim-plug
Shell
2
star
78

ls.zsh

Shell
2
star
79

vim-pt

💎 Vim plugin for the_platinum_searcher, 'pt'
Vim Script
2
star
80

go-colon

Parse colon-separated strings like PATH
Go
2
star
81

make_iap_request

Sample scripts which make the HTTP request to IAP-protected app
Python
2
star
82

enhancd3

WIP
Shell
2
star
83

action-github-comment

GitHub Actions to post a text to GitHub issue / pull request
Dockerfile
2
star
84

hashtag-bot

Go
2
star
85

open-link.sh

Shell
2
star
86

nginx-config-tester

Shell
2
star
87

lab-for-github-actions

Lab for GitHub Actions
Shell
1
star
88

talks

Hosted original sources related to my presentations and talks
Go
1
star
89

glob2regex

Shell
1
star
90

zpath

Shell
1
star
91

zplug-doctor

1
star
92

para

PAger wRApper written in golang
Go
1
star
93

noc

Count number of commands a day
C
1
star
94

changed-objects

Get changed objects in Git commit
Go
1
star
95

kube

DEPRECATED
Go
1
star
96

zsh_plugin

Shell
1
star
97

go-pathshorten

A go port of pathshorten() defined on Vim script
Go
1
star
98

.vim

Vim Script
1
star
99

git-relnotes

wip
Shell
1
star
100

til

Makefile
1
star