Code Monkey home page Code Monkey logo

enhancd's Introduction

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

enhancd's People

Contributors

acro5piano avatar aknep avatar aperum avatar asakasa avatar b4b4r07 avatar babarot avatar brendanfalk avatar chnb128 avatar crhg avatar d3dave avatar derphilipp avatar emres avatar gazorby avatar gitetsu avatar github-actions[bot] avatar gitter-badger avatar haletom avatar itoxiq avatar jorgebucaran avatar kan-bayashi avatar key-amb avatar kidonng avatar kshenoy avatar lordflashmeow avatar lukechilds avatar nexeck avatar peeviddy avatar ponko2 avatar timfee avatar usami-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

enhancd's Issues

Add case sensitivity as an option

It would be nice if I could toggle case sensitivity with a ENHANCD_CASE_SENSITIVE option.

For example I have /Backpack/backpack and to go to backpack I always have to type B/b.

If you allow ENHANCD_CASE_SENSITIVE, then I could send a PR too.

ENHANCD_FILTER queried in loading time and introduces a zshrc load order bug

I'm getting fzf-tmux:fzf: Invalid value as ENHANCD_FILTER

I'm using zplug on my .zshrc

source ~/.zplug/init.zsh
zplug "b4b4r07/enhancd", use:init.sh

fzf-tmux and fzf are perfectly fine on my system.

If I don't define ENHANCD_FILTER I also get and error:

# I've set ENHANCD_COMMAND=d
$ d
fzf-tmux:fzf:peco:fzy:percol:gof:pick:icepick:sentaku:selecta: Invalid value as ENHANCD_FILTER
$ zsh --version
zsh 5.2 (x86_64-apple-darwin15.0.0)

To manage separately Version 1 and Version 2

enhancd have a version 2 (v2) branch which is independent of the version 1 (v1). However, master branch have carelessly contained version 1 branch and bersion 2 branch.

  • master (v1 + v2)
  • v1 (v1)

v1 duplicates.

master ----------------- HEAD
v1           '-

So we want them to separate. In other words, we want to remove commits of version 1 from the master branch.

$ git rebase -i --root       # delete commits from 2aafc39 to dca011a
$ git add . && git commit -m "separate v2 from master"
$ git push -f

Cannot make it work with zplug

What did you expect to happen?
It should correctly load enhancd and give me the custom cd command

What actually happened?
Just nothing, it looks like enhancd won't load

Output

Last login: Wed Dec 12 11:52:06 on ttys008
[zplug] Loaded from cache (/Users/xxxxxx/.zplug/cache)
 Load "~/.zplug/repos/b4b4r07/enhancd/init.sh" (b4b4r07/enhancd)
[zplug] Run compinit
MacBook-Pro-de-xxxxxx%

Additional context
Here is my newly created .zshrc :

##################################
########## DEPENDENCIES ##########
##################################

# Load zplug
if [ ! -d ~/.zplug ]
then
  curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh
fi
source ~/.zplug/init.zsh

# Let zplug manage zplug updates
zplug 'zplug/zplug', hook-build:'zplug --self-manage'

##################################
############ PLUGINS #############
##################################

zplug "b4b4r07/enhancd", use:init.sh
if zplug check "b4b4r07/enhancd"; then
  #export ENHANCD_FILTER="fzf --height 50% --reverse --ansi --preview 'ls -l {}' --preview-window down"
  export ENHANCD_FILTER="fzf --height 50% --reverse --ansi"
  export ENHANCD_DOT_SHOW_FULLPATH=1
fi

# Install plugins if there are plugins that have not been installed
if ! zplug check; then
  printf "Some plugins need to be installed. Install plugins? [y/N]: "
  if read -q; then
    echo; zplug install
  fi
fi

# Source plugins and add commands to $PATH
zplug load --verbose

Even if I manually do source ~/.zplug/repos/b4b4r07/enhancd/init.sh it does not expose the cd command.

I'm on macOS Mojave (10.14.1) with zsh 5.6.2 (x86_64-apple-darwin18.0.0)

Thanks !

Antigen bundle stopped working

Hi,

Some recent upgrade of either antigen or enhancd caused it to stop working in my setup. When I delete ~/.antigen/repos/* and ~/.antigen/.cache and reinstall the bundle, the next shell I start has cd aliased to __enhancd::cd but it hangs without producing any output. Any shells after that do not have cd aliased to anything.

Fails silently with `set -o pipefail`

If I have in my .zshrc:

setopt pipe_fail  # return right-most command's non-zero return value

Then __enhancd::cd will fail silently, with 0 return value.

If I change the first lines of cd.sh to be:

function yelp () {
  # shellcheck disable=SC2154  # undeclared zsh variables in bash
  if [[ $BASH_VERSION ]]; then
    local file=${BASH_SOURCE[1]} func=${FUNCNAME[1]} line=${BASH_LINENO[0]}
  else  # zsh
    emulate -LR zsh  # Ensure 1-numbered arrays
    # $funcfiletrace has format:  file:line
    local file=${funcfiletrace[1]%:*} line=${funcfiletrace[1]##*:}
    local func=${funcstack[2]}
    [[ $func =~ / ]] && func=source  # $func may be filename. Use bash behaviour
  fi
  echo "${file##*/}:$func:$line $*" > /dev/tty
}

__enhancd::cd()
{
    trap yelp ERR

Then I see the following:

% ENHANCD_FILTER=fzy
% source init.sh
% cd
history.sh:__enhancd::history::list:25
cd.sh:__enhancd::cd:65
cd.sh:__enhancd::cd:91
%

The offending pipeline is at history.sh:__enhancd::history::list:25. If I change it to:

__enhancd::history::list()
{
    [[ -o pipefail ]] && local reset_pipefail=1
    set +o pipefail
    __enhancd::history::origin \
        | __enhancd::filter::reverse \
        | __enhancd::filter::unique \
        | __enhancd::filter::exists \
        | __enhancd::filter::fuzzy "$@" \
        | __enhancd::utils::grep -vx "$PWD"
    [[ $reset_pipefail ]] && set -o pipefail
}

Then the alias cd works as expected.

However, my debug then prints:

utils.sh:__enhancd::utils::grep:24

Installing requirements with Homebrew (macOS/OS X)

Short instruction for those on macOS/OS X (tested on OS X 10.11.6) using Bash.
Not an CLI expert, so there is most likely better ways to do this, or i got it wrong. But i got me up and running.

Requirements (using Homebrew and Bash)

Homebrew: https://brew.sh/

Basic install

# add the fzy brew tap to homebrew
$ brew tap jhawthorn/fzy

# install fzy and ccat with homebrew
$ brew install fzy ccat 

# alt: brew install fzy ccat percol peco fzf 
#  depending on which interactive filter you want to use

# install enhancd into your home directory (or a preferred directory)
$ cd ~  
$ git clone https://github.com/b4b4r07/enhancd

# if you want to hide the directory in the finder (gui)
$ chflags hidden enhancd  

# add enhancd to your bash profile (or sourced file of choice)
$ echo "source ~/enhancd/init.sh"  >> ~/.bash_profile

# reload your bash profile
$ source ~/.bash_profile

enhancd with autocd

I'm using this plugin very comfortably.
But I'm also using Zsh's autocd.
enhancd's function that memorize directory not seems to work when I change directory using autocd.

Then, I added below in my .zshrc.

autoload -uz add-zsh-hook
add-zsh-hook chpwd __enhancd::cd::after

It seems to work as I expected, but is this way correct?
Is there any way to use enhancd with autocd?

Thanks.

Have $HOME be first item in list

After typing cd, I'd like to be able to simply press enter to change to $HOME.

Could $HOME be the first item in the list if $PWD != $HOME?

enhancd, vi-mode and zplug

Hey, not sure if it's an issue with enhancd, vi-mode or zplug, but the following causes mayhem:

source ~/.zplug/zplug
zplug "b4b4r07/zplug"
zplug "plugins/vi-mode", from:oh-my-zsh
zplug "b4b4r07/enhancd", of:enhancd.sh
zplug check || zplug install
zplug load

The output is:

"^A\"-\"^C\" self-inser" undefined-key
"^D\" list-choice" undefined-key
"^E\"-\"^F\" self-inser" undefined-key
"^G\" list-expan" undefined-key
"^H\" backward-delete-cha" undefined-key
"^I\" expand-or-complet" undefined-key
"^J\" accept-lin" undefined-key
"^K\" self-inser" undefined-key
"^L\" clear-scree" undefined-key
"^M\" accept-lin" undefined-key
"^N\" down-histor" undefined-key
"^O\" self-inser" undefined-key
"^P\" up-histor" undefined-key
"^Q\" vi-quoted-inser" undefined-key
"^R\" redispla" undefined-key
"^S\"-\"^T\" self-inser" undefined-key
"^U\" vi-kill-lin" undefined-key
"^V\" vi-quoted-inser" undefined-key
"^W\" backward-kill-wor" undefined-key
"^X\" self-inser" undefined-key
"^X^R\" _read_com" undefined-key
"^X?\" _complete_debu" undefined-key
"^XC\" _correct_filenam" undefined-key
"^Xa\" _expand_alia" undefined-key
"^Xc\" _correct_wor" undefined-key
"^Xd\" _list_expansion" undefined-key
"^Xe\" _expand_wor" undefined-key
"^Xh\" _complete_hel" undefined-key
"^Xm\" _most_recent_fil" undefined-key
"^Xn\" _next_tag" undefined-key
"^Xt\" _complete_ta" undefined-key
"^X~\" _bash_list-choice" undefined-key
"^Y\"-\"^Z\" self-inser" undefined-key
"^[\" vi-cmd-mod" undefined-key
"^[,\" _history-complete-newe" undefined-key
"^[/\" _history-complete-olde" undefined-key
"^[OA\" up-line-or-histor" undefined-key
"^[OB\" down-line-or-histor" undefined-key
"^[OC\" vi-forward-cha" undefined-key
"^[OD\" vi-backward-cha" undefined-key
"^[[A\" up-line-or-histor" undefined-key
"^[[B\" down-line-or-histor" undefined-key
"^[[C\" vi-forward-cha" undefined-key
"^[[D\" vi-backward-cha" undefined-key
"^[~\" _bash_complete-wor" undefined-key
"^\\\\\\\\\"-\"~\" self-inser" undefined-key
"^?\" backward-delete-cha" undefined-key
"\M-^@\"-\"\M-^?\" self-inser" undefined-key

The second column all seemingly is missing it's last character. Any ideas?

Is this a bug? Unexpected behavior is occurred when running 'cd ..'

It seems that rindex() in awk script is wrong.
Current rindex() checks whether one string contains another string or not.

Is it correct behavior? Or just a bug?

I faced an issue. Following,

mkdir -p /foo/com.foo/baz
cd /foo/com.foo/baz
cd .. # then, select 'foo'
# expect $(pwd) == "/foo"
# actual $(pwd) == "/foo/com.foo"

enhancd is compatible with anyframe's cd commands ?

Hi ! I now try to use enhancd and anyframe with zplug.
Accrording to your zplug example, both enhancd and anyframe looks compatible.

But after installing enchancd, cdr and cd-ghq-repository of anyframe fail to execute with following error.

: no such file or directory

Is this occurred only my environment ?

Hang when checking unreachable automounts

What did you expect to happen?
I type cd <non-existent-dir> and I instantly get an error message that the directory doesn't exist.

What actually happened?
It hangs.

Output

Scroll to the end for the interesting line:

+ __enhancd::cd foo
+ local t arg=foo
+ local -i ret=0
+ __enhancd::utils::available
+ __enhancd::utils::filter fzy:fzf-tmux:fzf:peco:percol:gof:pick:icepick:sentaku:selecta
+ [[ -s /home/ravi/.config/enhancd/enhancd.log ]]
+ [[ -p /dev/stdin ]]
+ case "$arg" in
++ __enhancd::arguments::given foo
++ [[ -d foo ]]
++ __enhancd::history::list foo
++ __enhancd::filter::interactive
++ local list= filter
++ [[ -z '' ]]
++ __enhancd::filter::reverse
++ __enhancd::history::origin
++ local is_home=false
++ [[ '' == \-\-\h\o\m\e ]]
++ [[ -f /home/ravi/.config/enhancd/enhancd.log ]]
++ cat /home/ravi/.config/enhancd/enhancd.log
++ __enhancd::filter::exists
++ local line
++ read line
+++ cat
++ __enhancd::filter::fuzzy foo
++ __enhancd::filter::unique
++ [[ -z foo ]]
++ __enhancd::utils::grep -vx /home/ravi/bin
++ [[ 1 == 1 ]]
++ awk '!a[$0]++'
++ awk -f /home/ravi/.config/zsh/zplugin/plugins/b4b4r07---enhancd/src/share/fuzzy.awk -v search_string=foo
++ false
++ [[ -n -vx ]]
++ [[ -f -vx ]]
++ cat
++ command grep -E -vx /home/ravi/bin
++ [[ -n '' ]]
++ cat
++ [[ -n '' ]]
++ cat
++ awk -f /home/ravi/.config/zsh/zplugin/plugins/b4b4r07---enhancd/src/share/reverse.awk
++ [[ -d /home/ravi/bin ]]
++ echo /home/ravi/bin
++ read line
++ [[ -d /home/ravi ]]
++ echo /home/ravi
++ read line
++ [[ -d /media ]]
++ echo /media
++ read line
++ [[ -d /home/ravi/.dotfiles ]]
++ echo /home/ravi/.dotfiles
++ read line
++ [[ -d /home/ravi/code/scm_breeze ]]
++ echo /home/ravi/code/scm_breeze
++ read line
++ [[ -d /etc ]]
++ echo /etc
++ read line
++ [[ -d /home/ravi/etc ]]
++ echo /home/ravi/etc
++ read line
++ [[ -d /home/ravi/.local/share/zplugin/bin ]]
++ echo /home/ravi/.local/share/zplugin/bin
++ read line
++ [[ -d /home/ravi/code/scm_breeze/.git/refs/remotes/HaleTom ]]
++ echo /home/ravi/code/scm_breeze/.git/refs/remotes/HaleTom
++ read line
++ [[ -d /home/ravi/code/scm_breeze/.git/refs/remotes ]]
++ echo /home/ravi/code/scm_breeze/.git/refs/remotes
++ read line
++ [[ -d /home/ravi/code/scm_breeze/.git ]]
++ echo /home/ravi/code/scm_breeze/.git
++ read line
++ [[ -d /home/ravi/code/scm_breeze/test/support ]]
++ echo /home/ravi/code/scm_breeze/test/support
++ read line
++ [[ -d /home/ravi/code/scm_breeze/.git/refs/original ]]
++ read line
++ [[ -d /home/ravi/Documents/AI/math ]]
++ echo /home/ravi/Documents/AI/math
++ read line
++ [[ -d /home/ravi/code/scm_breeze/.git/refs/original/refs ]]
++ read line
++ [[ -d /home/ravi/code/scm_breeze/.git/refs ]]
++ echo /home/ravi/code/scm_breeze/.git/refs
++ read line
++ [[ -d /home/ravi/bin/git-hooks ]]
++ echo /home/ravi/bin/git-hooks
++ read line
++ [[ -d /usr/bin ]]
++ echo /usr/bin
++ read line
++ [[ -d / ]]
++ echo /
++ read line
++ [[ -d /media/backup/btrbk/rootfs ]]

The last directory is on a systemd automounted USB disk: /media/backup.

It waits about 30 seconds before checking the next directory.

Any unreachable NFS mounts will have the same problem.

Feature suggestion:
Implement a blacklist of directories to not check as they are likely to hang.

Bug that the log disappears

$ ls -l $ENHANCD_LOG
-rw-r--r--  1 b4b4r07  staff  8554 Aug 22 15:08 /Users/b4b4r07/.enhancd/enhancd.log
$ echo $HOME | cd
: no such file or directory
$ ls -l $ENHANCD_LOG
-rw-r--r--  1 b4b4r07  staff  15 Aug 22 15:25 /Users/b4b4r07/.enhancd/enhancd.log

What happened to the fisherman version?

Question
I really want to use enhancd but I use the fish shell. So I looked through issues for "fish" and realized that a while ago, fish support got split into a fisherman package. Unfortunately, the link to that package is broken. Any idea where I can find that repo? Thanks!

Exit on start (no such file: enhancd.t)

log:

$ zsh
Creating a zgen save
/Users/eru/.zgen/b4b4r07/enhancd-master/enhancd_test.sh:.:9: no such file or directory: /Users/eru/.zgen/b4b4r07/enhancd-master/enhancd.t

workaround:

$ ln -s ~/.zgen/b4b4r07/enhancd-master/{enhancd.sh,init.zsh}
$ zgen reset

cd not displaying filter results from fzf

First of all this seems to be awesome and thank you in advance for creating that project :)

What did you expect to happen?
type cd <Tab> and see interactive list of directories provided by fzf

What actually happened?
I see original list of directories just like using standard cd command.

Any ides how can I debug this?
Here is my zshrc: https://github.com/ghostbuster91/dot-files/blob/zplug/.zshrc

Edit:
So I noticed that it works when I press enter after typing cd, is this a desired behavior? Is there an option to change the action it to <TAB> key?

Partial matching?

Mostly, wondering why e.g. cd down doesn't suggest ~/Downloads and if there's anything I can do about that?

Support cd -P and other builtin command options

What did you expect to happen?
I can use the command-line options of the builtin cd command. $PWD is changed with no output.:

% builtin cd -P -- bin
%

What actually happened?

% cd -P -- bin
-P: no such option

Additional context
The -- or "end of options should also be supported to cover the edge case where a directory is called -P or -.

Arguments of the shell's builtin cd should be collected and then passed to the underlying builtin command:

bash: cd [-L|[-P [-e]] [-@]] [dir]
zsh: cd [ -qsLP ] [ arg ]

Performance issues with remote locations

I regularly work with remote locations mounted locally (NFS. sshfs...). These have variable latency due to network and I/O load.

After using enhancd for a few weeks and populating enhanced.log with over 3000 entries, issuing a simple cd takes between 3-5 seconds and over 10 seconds when the remote locations are under medium load. This happens even when only issuing commands that primarily target local directories.

I assume most of the delay originates from enhancd checking which directories are still reachable and slowing down when validating remote locations.
Is there any way to profile enhancd and pinpoint the source of slowness?

Contrasting this with fasd, that has been a companion for many years without major performance issues, I find 2-3 seconds a bit too much to be bearable on such an essential command.
As such is there any way to tweak enhancd to avoid hitting these performance issues?

I'm very much enjoying the interaction but the delay is ruining the experience.

Seems to break tmux initial directory

It appears that when I start a new tmux session while having loaded enhancd, the initial working directory is not set properly - it will always be '~'. I have not done any further diagnosing yet. I am on OSX.

fzf mode

I want to use --expect option in fzf. For instance, giving --bind "enter:execute(less {})" as an argument to the fzf command enable you to list the directory under a cursor through less.

occasional high cpu usage + filling up hard drive

Once out of about 10 times I use cd::cd, my cpu usage goes super high, and enhancd.log fills up whatever space i have left on my hard drive. When I hear the fans spin, I have to killall cat to go back to normal. In addition, while this is going on, any other shell I try cd in, it hangs. How can I help debug where my issue is?

Cleaning enhancd cache

As the title says.
How can I delete paths cached by enhancd?

EDIT: $HOME/.enhancd/enhancd.log is the answer, my bad.

Case-insensitive autocomplete?

Thanks for this great module! I am used to and greatly enjoy being able to case-insensitively autocomplete directory names. e.g. if I am in ~ which has a Developer folder, if I type cd dev<tab>, it'll autocomplete to cd Developer/.

Unfortunately, enhancd breaks this case-insensitive autocomplete. Would it be possible for enhancd to support this somehow? I'd be happy to see about adding support myself if you tell me it's possible/desirable :)

cd completion also display files

Hi,

When enhancd is activated, the cd completion doesn't just select directories but also files.
I did a clean install of zsh on an ubuntu docker container and imported enhancd in it (meaning I don't have any special conf).

% whence -v cd
cd is an alias for __enhancd::cd
% echo 'test' > file
% mkdir dir
% cd
dir/  file

possible to list hidden directories?

Hello,

I love your work however I had a question is it possible to also list hidden directories?
And does it only work from the home directory or did I configure something wrong?

Thanks!

Invalid value as ENHANCD_FILTER over ssh

When I run cd on a remote system over ssh, I got the following error

fzf-tmux:fzf:peco:fzy:percol:gof:pick:icepick:sentaku:selecta: Invalid value as ENHANCD_FILTER

No error when I run locally on the same system. which fzf gives the path to fzf correctly.

Increase "cd -" numbers

It's proposal.

I wanna change this "10" history to 100 or over.
How can I do this?
How about add this number to Configuration ENV variable?

-: no such file or directory

I can't seem to get cd - working properly while using enhancd.

In zsh:

 ~/Documents> cd -
-: no such file or directory
 ~/Documents>

The same command also fails in bash while using enhancd:

~/Documents$ cd -
-: no such file or directory

Using $OLDPWD works in both zsh and bash:

 ~/Documents > cd $OLDPWD
 ~ > 

I can reproduce this with a fairly minimal zshrc:

export PATH=$HOME/bin:/usr/local/bin:$PATH
echo Running test zshrc
plugins=()
prompt_context(){}

source ~/.enhancd/init.sh
export ENHANCD_FILTER=fzy

Check cd function:

 ~/Documents > type cd
cd is an alias for __enhancd::cd

After realising the cd function was being replaced by enhancd, I tried disabling enhanced and then cd - worked properly.

Do you have any suggestions what might cause this?

Versions:
enhancd 2.2.2
zsh 5.4.2
Ubuntu 18.04
gnome-terminal 3.28.2

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.