Skip to content

Commit

Permalink
Disable fzf shell integration for bash till fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
mehran-prs committed May 21, 2024
1 parent 9594eb0 commit e13046a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
30 changes: 12 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Snip is a simple and minimal command-line snippet manager.

- View your snippets on command line and also manage them (create, edit, delete) using your favorite editor.
- Command-line auto-completion for the snippets names (supports `bash`, `zsh`, `fish` and `powershell`).
- Seamlessly integration with `fzf` to provide fuzzy completion.
- Syntax highlighting (using `bat` and `glow` by default) and Git integration
- Seamlessly integration with `fzf` to provide fuzzy completion(currently supports `zsh` shell).
- Syntax highlighting and Git integration

### How to use

Expand All @@ -31,8 +31,7 @@ Snip is a simple and minimal command-line snippet manager.
- Run `snip {snippet_name}` to view a snippet.
- If you've
enabled [`fzf` shell integration](https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration) in
you bash or zsh,
you can find snippets by fuzzy completion. e.g., type `snip **` and pres tab.
you `zsh` shell, you can find snippets by fuzzy completion. e.g., type `snip **` and pres tab.

![snip view snippets](docs/images/snip-view.gif)

Expand Down Expand Up @@ -74,10 +73,10 @@ git push -u origin main
### Getting started

- [Install the snip command](#installation).
- [Enable auto-completion](#setting-up-shell-integration)
- [Enable auto-completion](#shell-integration)
- (optional) Set custom [snippets directory path](#customization).
- (optional) [Enable syntax highlighting](#enable-syntax-highlighting)
- (optional) [Enable fuzzy completion if your shell is bash or zsh](#enable-fuzzy-completion).
- (optional) [Enable syntax highlighting](#enable-syntax-highlighting) (recommended)
- (optional) [Enable fuzzy completion](#enable-fuzzy-completion) if your shell is `zsh` (recommended).
- [Use `snip`](#how-to-use) :))

### Installation
Expand All @@ -91,7 +90,7 @@ go install -ldflags "-X main.Version=main -X main.Date=`date +'%FT%TZ%z'`" gith
Or get pre-compiled executables [here](http://github.com/mehran-prs/snip/releases)

> [!IMPORTANT]
> To set up completion, see the [instructions below](#setting-up-shell-integration).
> To set up completion, see the [instructions below](#shell-integration).
### Shell integration

Expand All @@ -100,7 +99,7 @@ Add the following line to your shell configuration file.
* bash
```sh
# Set up snip regular and fuzzy completion
eval "$(snip completion bash)"
source <(snip completion bash)
```
* zsh
```sh
Expand Down Expand Up @@ -132,7 +131,6 @@ Set the following env variables to customize snip(e.g., put `export SNIP_DIR=/pa
| SNIP_VERBOSE | "" | Enable verbose mode (values: `true`) |
| SNIP_LOG_TMP_FILENAME | "" | Set path to a temporary log file. it's helpful in autocompletion debugging |


### Commands

```bash
Expand All @@ -152,6 +150,7 @@ Available Commands:
Flags:
-h, --help help for snip
```

### Enable syntax highlighting

- Install [`bat`](https://github.com/sharkdp/bat) and [`glow`](https://github.com/charmbracelet/glow).
Expand All @@ -169,16 +168,11 @@ export SNIP_MARKDOWN_VIEWER_CMD="glow"
### Enable fuzzy completion

- Install [`fzf`](https://github.com/junegunn/fzf) to enable fuzzy completion.
- Set up [`fzf` shell integration](https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration)

> [!Note]
> Fuzzy completion is supported just in bash and zsh.

> [!NOTE]
> In your shell configuration, `fzf` shell integration needs to be enabled before the `snip` shell integration.
> Currently fuzzy completion is supported just in zsh.
- Install [`fzf`](https://github.com/junegunn/fzf) to enable fuzzy completion.
- Set up [`fzf` shell integration](https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration)

### Multi-tenancy (Advanced usage)

Expand Down
2 changes: 1 addition & 1 deletion fzf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ _fzf_complete_%[1]s() {
_fzf_path_completion $(%[1]s dir $prefix) "$@"
}
type __fzf_defc &>/dev/null && __fzf_defc %[1]s _fzf_complete_%[1]s "-o default -o bashdefault"
complete -F _fzf_complete_%[1]s -o default -o bashdefault %[1]s
`, appName)
}
2 changes: 1 addition & 1 deletion fzf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _fzf_complete_abc() {
_fzf_path_completion $(abc dir $prefix) "$@"
}
type __fzf_defc &>/dev/null && __fzf_defc abc _fzf_complete_abc "-o default -o bashdefault"
complete -F _fzf_complete_abc -o default -o bashdefault abc
`
assertEqual(t, genFzfZshCompletion("abc"), zshRes)
assertEqual(t, genFzfBashCompletion("abc"), bashRes)
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ func CmdCompletionGenerator(cmd *cobra.Command, args []string) error {
if err := cmd.Root().GenBashCompletionV2(os.Stdout, true); err != nil {
return err
}
// In bash, we support fzf too:
fmt.Println(genFzfBashCompletion(cmd.Root().Name()))
// Currently in bash we do not support fzf, because when we define the fzf function and enable completion
// for it, it'll override the original completion function, this is while we need to just call it when
// user's input ends with "**" to the fzf trigger value.
// TODO: enable completion for bash, but keep the original completion too.
//fmt.Println(genFzfBashCompletion(cmd.Root().Name()))
case "zsh":
if err := cmd.Root().GenZshCompletion(os.Stdout); err != nil {
return err
Expand Down

0 comments on commit e13046a

Please sign in to comment.