Skip to content

Commit

Permalink
- Improved documentation of multiple choices
Browse files Browse the repository at this point in the history
- Changed default key binding to Prefix+C-h because it is easy to type and was not used yet in standard tmux configurations
- Better error handling
- Changed default editor cmd to open vim
  • Loading branch information
alberti42 committed Jan 6, 2025
1 parent 6086ec3 commit a108cd4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The plugin was originally inspired by [tmux-fzf-url](https://github.com/wfxr/tmu

## 🌟 Features

- **Fuzzy Search Links**: Quickly locate and open links appearing in your terminal output.
- **Fuzzy Search Links**: Quickly locate and open links appearing in your terminal output. Support multiple simultaneous choices.
- **Default and Custom Schemes**: Use pre-configured schemes or define your own with custom handlers for pre- and post-processing.
- **Integration with tmux Popup Windows**: Provides a seamless user experience within tmux sessions.
- **Flexible Open Commands**: Configure your favorite editor, browser, or custom command to open links.
Expand Down Expand Up @@ -127,7 +127,7 @@ Default options are already provided. However, you can customize all options by

```tmux
# === tmux-fzf-links ===
# set-option -g @fzf-links-key o
# set-option -g @fzf-links-key C-h
# set-option -g @fzf-links-history-lines "0"
set-option -g @fzf-links-editor-open-cmd "tmux new-window -n 'emacs' /usr/local/bin/emacs +%line '%file'"
set-option -g @fzf-links-browser-open-cmd "/path/to/browser '%url'"
Expand All @@ -140,7 +140,7 @@ set-option -g @fzf-links-python "python3"
# set-option -g @fzf-links-python-path "~/.virtualenvs/my_special_venv/lib/python3.11/site-packages"
# set-option -g @fzf-links-user-schemes-path "~/.tmux/plugins/tmux-fzf-links/user_schemes/user_schemes.py"
set-option -g @fzf-links-use-colors on
# set-option -g @fzf-links-ls-colors-filename "~/.cache/zinit/ls_colors.zsh"
# set-option -g @fzf-links-ls-colors-filename "~/.cache/tmux-fzf-links/cached_ls_colors.txt"

run-shell "~/.local/share/tmux-fzf-links/fzf-links.tmux"
```
Expand Down Expand Up @@ -184,7 +184,12 @@ Comment out the options you find useful and replace the placeholders with approp

4. **`history-lines`**: An integer number determining how many extra lines of history to consider. By default, it is set to 0.

5. **`@fzf-links-ls-colors-filename`**: This option is not strictly necessary if `$LS_COLORS` is available in the environment. Use it only if `tmux` is launched directly as the first process in the terminal, bypassing the shell initialization where `$LS_COLORS` is set.
5. **`@fzf-links-ls-colors-filename`**: A file containing the content of $LS_COLORS. For example, you can save $LS_COLORS to a cached file using:
```bash
printenv LS_COLORS > cached_ls_colors.txt
```

Using such a file is not strictly necessary if `$LS_COLORS` is available in the environment. Use `@fzf-links-ls-colors-filename` only if `tmux` is launched directly as the first process in the terminal, bypassing the shell initialization where `$LS_COLORS` is set.

6. **`@fzf-links-path-extension`**: This option is also not strictly necessary. It is only required if `tmux` binary is not in the `$PATH` that was available when `tmux` started. The plugin only requires these two processes.

Expand All @@ -201,9 +206,10 @@ Comment out the options you find useful and replace the placeholders with approp
## 🖱️ Usage

1. Start tmux.
2. Press the configured key (default: `o` as for `open`) to activate **tmux-fzf-links**.
2. Press `<prefix>` + the configured key (default: `C-h`; an easy-to-type key sequence; you can change it) to activate **tmux-fzf-links**.
3. Select a link using the fuzzy search interface.
4. The link will be opened using the configured command (editor, browser, or custom).
4. Press `TAB` or `SHIFT-TAB` to select or deselect multiple choices
4. The selected links will be opened using the configured command (editor, browser, or custom).

---

Expand Down
12 changes: 6 additions & 6 deletions fzf-links.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ tmux_get() {
}

# Fetch Tmux options with defaults
key=$(tmux_get '@fzf-links-key' 'o')
key=$(tmux_get '@fzf-links-key' 'C-h')
history_lines=$(tmux_get '@fzf-links-history-lines' '0')
editor_open_cmd=$(tmux_get '@fzf-links-editor-open-cmd' '')
browser_open_cmd=$(tmux_get '@fzf-links-browser-open-cmd' '')
fzf_display_options=$(tmux_get '@fzf-links-fzf-display-options' '-w 100% -h 15% --multi -0 --no-preview')
editor_open_cmd=$(tmux_get '@fzf-links-editor-open-cmd' "tmux new-window -n 'vim' vim +%line '%file'")
browser_open_cmd=$(tmux_get '@fzf-links-browser-open-cmd' "firefox '%url'")
fzf_display_options=$(tmux_get '@fzf-links-fzf-display-options' '-w 100% --maxnum-displayed 15 --multi -0 --no-preview')
path_extension=$(tmux_get '@fzf-links-path-extension' '')
loglevel_tmux=$(tmux_get '@fzf-links-loglevel-tmux' 'WARNING')
loglevel_file=$(tmux_get '@fzf-links-loglevel-file' 'WARNING')
loglevel_file=$(tmux_get '@fzf-links-loglevel-file' 'DEBUG')
log_filename=$(tmux_get '@fzf-links-log-filename' '')
python=$(tmux_get '@fzf-links-python' 'python3')
python_path=$(tmux_get '@fzf-links-python-path' '')
Expand All @@ -45,7 +45,7 @@ ls_colors_filename=$(eval echo "$ls_colors_filename")
user_schemes_path=$(eval echo "$user_schemes_path")

# Bind the key in Tmux to run the Python script
tmux bind-key "$key" run-shell "
tmux bind-key -N "Open links with fuzzy finder (tmux-fzf-links plugin)" "$key" run-shell "
if [[ ! -x \"$python\" ]]; then
tmux display-message -d 0 \"fzf-links: no executable python found at the location: $python_path\"
exit 0
Expand Down
8 changes: 7 additions & 1 deletion tmux-fzf-links-python-pkg/tmux_fzf_links/opener.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#===============================================================================

import shutil
import logging
import re
import os
import subprocess
Expand Down Expand Up @@ -73,6 +74,7 @@ def open_link(editor_open_cmd:str, browser_open_cmd:str, post_handled_match:Post

args = shlex.split(cmd)

logging.debug(os.environ["PATH"])
try:
# Run the command and capture stdout and stderr
proc = subprocess.Popen(
Expand All @@ -90,5 +92,9 @@ def open_link(editor_open_cmd:str, browser_open_cmd:str, post_handled_match:Post
if proc.returncode != 0:
raise CommandFailed(f"return code {proc.returncode}: {stderr.decode('utf-8')}")

except FileNotFoundError as e:
raise CommandFailed(f'could not find "{args[0]}" in the path')

except Exception as e:
raise CommandFailed(f"failed to execute command '{" ".join(post_handled_match)}': {e}")
raise CommandFailed(f'failed to execute command "{cmd}"')

0 comments on commit a108cd4

Please sign in to comment.