From fbd755108892388d171336b07b5735a433ec710c Mon Sep 17 00:00:00 2001 From: Christian Stigen Larsen Date: Tue, 15 Mar 2016 00:49:31 +0100 Subject: [PATCH] Adds peek command, opens quicklook on osx --- README.md | 2 ++ open.tmux | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 22f51cc..4b492da 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ In tmux copy mode: - `o` - "open" a highlighted selection with the system default program. `open` for OS X or `xdg-open` for Linux. +- `O` - "peek" a highlighted selection with the system default program. + `qlmanage` (quicklook) for OS X (unsupported on Linux, at the moment). - `Ctrl-o` - open a highlighted selection with the `$EDITOR` ### Examples diff --git a/open.tmux b/open.tmux index 1c49585..87324dd 100755 --- a/open.tmux +++ b/open.tmux @@ -11,6 +11,9 @@ default_open_editor_key="C-o" open_editor_option="@open-editor" open_editor_override="@open-editor-command" +default_peek_key="O" +peek_option="@peek" + command_exists() { local command="$1" type "$command" >/dev/null 2>&1 @@ -83,6 +86,15 @@ generate_editor_command() { echo "xargs -I {} tmux send-keys '$editor -- \"{}\"'; tmux send-keys 'C-m'" } +generate_peek_command() { + if is_osx; then + echo "$(command_generator "qlmanage -p >/dev/null 2>&1")" + else + # error command for non-OSX (I don't know the Linux peek command) + "$CURRENT_DIR/scripts/tmux_open_error_message.sh" "qlmanage" + fi +} + set_copy_mode_open_bindings() { local open_command="$(generate_open_command)" local key_bindings=$(get_tmux_option "$open_option" "$default_open_key") @@ -103,6 +115,16 @@ set_copy_mode_open_editor_bindings() { done } +set_copy_mode_peek_bindings() { + local peek_command="$(generate_peek_command)" + local key_bindings=$(get_tmux_option "$peek_option" "$default_peek_key") + local key + for key in $key_bindings; do + tmux bind-key -t vi-copy "$key" copy-pipe "$peek_command" + tmux bind-key -t emacs-copy "$key" copy-pipe "$peek_command" + done +} + set_copy_mode_open_search_bindings() { local stored_engine_vars="$(stored_engine_vars)" local engine_var @@ -121,6 +143,7 @@ main() { set_copy_mode_open_bindings set_copy_mode_open_editor_bindings set_copy_mode_open_search_bindings + set_copy_mode_peek_bindings } main