├── .github └── FUNDING.yml ├── LICENSE ├── PKGBUILD ├── README.md ├── clean.py ├── demo.webp ├── icd.fish └── icd.plugin.zsh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: g-plane 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-present Pig Fang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: Pig Fang 2 | pkgname=icd 3 | pkgver=0.2.1 4 | pkgrel=1 5 | pkgdesc='Powerful `cd` command with fuzzy-search tool.' 6 | 7 | arch=('any') 8 | url="https://github.com/g-plane/$pkgname" 9 | source=("https://github.com/g-plane/$pkgname/archive/v$pkgver.tar.gz") 10 | sha256sums=('4ad64ebd0afcb99f8def17044d2255c34fd3bdf16683ff938829b64a1048fdf2') 11 | license=('MIT') 12 | depends=('fzf') 13 | optdepends=('ripgrep' 'grep') 14 | 15 | package() { 16 | cd $srcdir/$pkgname-$pkgver/ 17 | 18 | install -Dm644 $pkgname.plugin.zsh $pkgdir/usr/share/zsh/scripts/$pkgname/$pkgname.plugin.zsh 19 | install -dm755 $pkgdir/usr/share/fish/vendor_functions.d 20 | install -Dm644 icd.fish $pkgdir/usr/share/fish/vendor_functions.d/icd.fish 21 | install -Dm644 LICENSE $pkgdir/usr/share/licenses/$pkgname/LICENSE 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # icd 2 | 3 | Powerful `cd` command with fuzzy-search tool. 4 | 5 | It's similar with [enhancd](https://github.com/b4b4r07/enhancd), but faster and more lightweight. 6 | 7 | ![](./demo.webp) 8 | 9 | ## Requirements 10 | 11 | First, you need to install [fzf](https://github.com/junegunn/fzf) for fuzzy searching. 12 | 13 | Second, you can install [ripgrep](https://github.com/BurntSushi/ripgrep). 14 | This is optional, but recommended. If don't have ripgrep, you can set `$ICD_GREP` to `grep` like this: 15 | 16 | ```sh 17 | export ICD_GREP=grep 18 | ``` 19 | 20 | icd will fall back to use `grep` command instead of `rg`. 21 | 22 | ## Install 23 | 24 | ### Oh My Zsh 25 | 26 | Run this command: 27 | 28 | ``` 29 | git clone https://github.com/g-plane/icd.git $ZSH_CUSTOM/plugins 30 | ``` 31 | 32 | Then, update your `.zshrc` like this: 33 | 34 | ```diff 35 | plugins=( 36 | # ... your other plugins 37 | + icd 38 | ) 39 | ``` 40 | 41 | ### zinit 42 | 43 | Update your `.zshrc` with following line: 44 | 45 | ```sh 46 | zinit light g-plane/icd 47 | ``` 48 | 49 | ### zplug 50 | 51 | Update your `.zshrc` with following line: 52 | 53 | ```sh 54 | zplug "g-plane/icd" 55 | ``` 56 | 57 | ### Fish 58 | 59 | Copy `icd.fish` to `~/.config/fish/functions` directory. 60 | 61 | Then, add alias to your `~/.config/fish/config/config.fish`: 62 | 63 | ```shell 64 | alias cd icd 65 | ``` 66 | 67 | ## License 68 | 69 | MIT License 70 | 71 | 2020-present (c) Pig Fang 72 | -------------------------------------------------------------------------------- /clean.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import PurePath 3 | 4 | with open(PurePath(os.environ['HOME'], '.history.icd'), 'r+') as f: 5 | lines = f.readlines() 6 | f.seek(0) 7 | f.truncate() 8 | f.writelines(filter(lambda s: os.path.exists(s.strip()), lines)) 9 | -------------------------------------------------------------------------------- /demo.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/g-plane/icd/8ee8395a129090b2c10a9dd76aa27712da458d16/demo.webp -------------------------------------------------------------------------------- /icd.fish: -------------------------------------------------------------------------------- 1 | function icd 2 | if test "$ICD_GREP" = "grep" 3 | set -f grep_tool "grep" 4 | set -f grep_tool_opts "-x" 5 | else 6 | set -f grep_tool "rg" 7 | set -f grep_tool_opts "-xN" 8 | end 9 | 10 | set -f history_file "$HOME/.history.icd" 11 | if not test -f $history_file 12 | touch $history_file 13 | end 14 | 15 | if test -z $argv[1] 16 | set -f selected (cat $history_file | fzf --scheme=path --height=20% --layout=reverse) 17 | else 18 | if test -d $argv[1] 19 | set -f selected (realpath $argv[1]) 20 | else 21 | set -f selected (cat $history_file | fzf --scheme=path --height=20% --layout=reverse --query $argv[1]) 22 | end 23 | end 24 | 25 | if test -n $selected 26 | set -l searched ($grep_tool $grep_tool_opts $selected $history_file) 27 | if string match -q -v '/tmp*' $selected; and test "$searched" != $selected 28 | echo $selected >> $history_file 29 | end 30 | builtin cd $selected 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /icd.plugin.zsh: -------------------------------------------------------------------------------- 1 | icd() { 2 | if [[ $ICD_GREP == "grep" ]]; then 3 | local grep_tool="grep" 4 | local grep_tool_opts="-x" 5 | else 6 | local grep_tool="rg" 7 | local grep_tool_opts="-xN" 8 | fi 9 | 10 | local history_file="$HOME/.history.icd" 11 | if [[ ! -f $history_file ]]; then 12 | touch $history_file 13 | fi 14 | 15 | if [[ $1 != "" ]]; then 16 | if [[ -d $1 ]]; then 17 | local selected=$(realpath $1) 18 | else 19 | local selected=$(cat $history_file | fzf --scheme=path --height=20% --layout=reverse --query $1) 20 | fi 21 | else 22 | local selected=$(cat $history_file | fzf --scheme=path --height=20% --layout=reverse) 23 | fi 24 | 25 | if [[ $selected != "" ]]; then 26 | if [[ ! $selected =~ ^/tmp && $($grep_tool $grep_tool_opts $selected $history_file) != $selected ]]; then 27 | echo $selected >> $history_file 28 | fi 29 | builtin cd $selected 30 | fi 31 | } 32 | 33 | alias cd="icd" 34 | --------------------------------------------------------------------------------