Giter VIP home page Giter VIP logo

enhancd's Introduction

Description | Features | Requirements | Usage
Installation | Configuration | References | License


๐Ÿš€ enhancd v2 is ...

A next-generation cd command with an interactive filter โœจ

๐Ÿ“ Description

cd command is one of the frequently used commands.

Nevertheless, it is not so easy to handle unfortunately. A directory path given as an argument to cd command must be a valid path that exists and is able to resolve. In other words, you cannot pass a partial path such as "dir" (you are in /home/lisa, dir is /home/lisa/work/dir) to cd command.

The new cd command called "enhancd" enhanced the flexibility and usability for a user. enhancd will memorize all directories visited by a user and use it for the pathname resolution. If the log of enhancd have more than one directory path with the same name, enhancd will pass the candidate directories list to the filter within the ENHANCD_FILTER environment variable in order to narrow it down to one directory.

Thanks to this mechanism, the user can intuitively and easily change the directory you want to go.

DEMO:

:trollface: Features

  • Go to the visited directory in the past
  • Easy to filter, using your favorite filter
  • Work on Bash, Zsh and Fish ๐ŸŸ
  • Go back to a specific parent directory like zsh-bd
  • Fuzzy search in a similar name directory
  • Support standard input (echo $HOME | cd is ok)

Fuzzy search

You can fuzzy-search a directory name you want to run cd. For example, a word "text" is expand to "test" and "txt".

๐Ÿ’“ Requirements

  • An interactive filter

    Choose any one from among these.

  • AWK (nawk or gawk)

๐Ÿ” Usage

Under Zsh or Bourne shells such as sh and bash, you would use enhancd.sh. Under fish shell, enhancd.fish.

$ source ./enhancd.sh

Because enhancd functions must be executed in the context of the current shell, you should run something like above command.

The basic usage of the cd command that has been implemented by enhancd is the same as the normal builtin cd command.

$ cd [-|..] <directroy>

If no arguments are given, enhancd cd command will display a list of the directory you've visited once, encourage you to filter the directory that you want to move.

$ cd
  ...
  /home/lisa/src/github.com/b4b4r07/enhancd/zsh
  /home/lisa/src/github.com/b4b4r07/gotcha
  /home/lisa/src/github.com/b4b4r07/blog/public
  /home/lisa/src/github.com/b4b4r07/blog
  /home/lisa/src/github.com/b4b4r07/link_test
  /home/lisa/src/github.com/b4b4r07
  /home/lisa/Dropbox/etc/dotfiles
  /home/lisa/src/github.com/b4b4r07/enhancd
> /home/lisa
  247/247
> _

The ENHANCD_FILTER variable is specified as a list of one or more visual filter command such as this separated by colon (:) characters.

It is likely the only environment variable you'll need to set when starting enhancd.

$ ENHANCD_FILTER=peco; export ENHANCD_FILTER

Since the $ENHANCD_FILTER variable can be a list, enhancd will use $ENHANCD_FILTER to mean the first element unless otherwise specified.

$ ENHANCD_FILTER=fzf:peco:gof
$ export ENHANCD_FILTER

Options

  • Hyphen (-)

    When enhancd takes a hyphen (-) string as an argument, it searchs from the last 10 directory items in the log. With it, you can search easily the directory you used last.

     $ cd -
       /home/lisa/Dropbox/etc/dotfiles
       /home/lisa/Dropbox
       /home/lisa/src/github.com
       /home/lisa/src/github.com/b4b4r07/cli
       /home
       /home/lisa/src
       /home/lisa/src/github.com/b4b4r07/enhancd
       /home/lisa/src/github.com/b4b4r07/gotcha
       /home/lisa/src/github.com/b4b4r07
     > /home/lisa/src/github.com/b4b4r07/portfolio
       10/10
     > _	

    Then, since the current directory will be delete from the candidate, you just press Enter key to return to the previous directory after type cd - ($PWD is /home/lisa, $OLDPWD is /home/lisa/src/github.com/b4b4r07/portfolio).

  • Double-dot (..)

    From the beginning, .. means the directory's parent directory, that is, the directory that contains it. When enhancd takes a double-dot (..) string as an argument, it behaves like a zsh-bd plugin. In short, you can jump back to a specific directory, without doing cd ../../...

    For example, when you are in /home/lisa/src/github.com/b4b4r07/enhancd, type cd .. in your terminal:

     $ cd ..
       /
       home
       lisa
       src
       github.com
     > b4b4r07
       6/6
     > _

    When moving to the parent directory, the current directory is removed from the candidate.

๐Ÿ“ฆ Installation

Give me a trial!

  • Install with zplug:

    enhancd can be installed by adding following to your .zshrc file in the same function you're doing your other zplug load calls in.

     $ zplug "b4b4r07/enhancd", of:enhancd.sh
  • Install with git clone:

     $ git clone https://github.com/b4b4r07/enhancd
     $ source /path/to/enhancd/enhancd.sh

๐Ÿ”ง Configurations

ENHANCD_DIR

The ENHANCD_DIR variable is a base directory path. It defaults to ~/.enhancd.

ENHANCD_FILTER

  1. What is ENHANCD_FILTER?

    The ENHANCD_FILTER is an environment variable. It looks exactly like the PATH variable containing with many different filters such as peco concatenated using ':'.

  2. How to set the ENHANCD_FILTER variable?

    Setting the ENHANCD_FILTER variable is exactly like setting the PATH variable. For example:

    $ export ENHANCD_FILTER="/usr/local/bin/peco:fzf:non-existing-filter"

    This above command will hold good till the session is closed. In order to make this change permanent, we need to put this command in the appropriate profile file. The ENHANCD_FILTER command in this example is set with 3 components: /usr/local/bin/peco followed by fzf and the not-existing-filter.

    enhancd narrows the ENHANCD_FILTER variable down to one. However, the command does not exist can not be the candidate.

    Let us try to test this ENHANCD_FILTER variable.

    $ cd

    If cd command does not return error, the settings of ENHANCD_FILTER is success.

  3. How to find the value of the ENHANCD_FILTER variable?

    $ echo $ENHANCD_FILTER
    /usr/local/bin/peco:fzf:non-existing-filter

ENHANCD_COMMAND

The ENHANCD_COMMAND environment variable is to change the command name of enhancd cd. It defaults to cd.

When the command name is changed, you should set new command name to ENHANCD_COMMAND, export it and restart your shell (reload enhancd.sh).

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

The ENHANCD_COMMAND may only hold one command name. Thus, in the previous example, it is true that enhancd cd command name is ecd, but it is not cd (cd is turned into original builtin cd).

Besides putting a setting such as this one in your ~/.bash_profile or .zshenv would be a good idea:

ENHANCD_COMMAND=ecd; export ENHANCD_COMMAND

ENHANCD_DISABLE_DOT

If you don't want to use the interactive filter, when specifing a double dot (..), you should set not zero value to $ENHANCD_DISABLE_DOT. Dedaluts to 0.

ENHANCD_DISABLE_HYPHEN

This option is similar to ENHANCD_DISABLE_DOT. Defaults to 0.

๐Ÿ“š References

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.

๐ŸŽซ License

MIT ยฉ๏ธ BABAROT (a.k.a. b4b4r07)

enhancd's People

Contributors

babarot avatar b4b4r07 avatar gitter-badger avatar gitetsu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.