From 79ee5abc7c9b19833846530cdb4fc4364999a97e Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 17 Apr 2021 13:14:57 +0200 Subject: [PATCH] Installation using cargo install --- src/swapper.rs | 11 +++++++++-- tmux-thumbs.sh | 2 +- tmux-thumbs.tmux | 8 +------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/swapper.rs b/src/swapper.rs index 707d0eb..3368929 100644 --- a/src/swapper.rs +++ b/src/swapper.rs @@ -209,12 +209,19 @@ impl<'a> Swapper<'a> { "".to_string() }; + let cargo_home = option_env!("CARGO_HOME"); + let binary = if let Some(home) = cargo_home { + format!("{}/bin/thumbs", home) + } else { + format!("{}/target/release/thumbs", self.dir) + }; + let pane_command = format!( - "tmux capture-pane -et {active_pane_id} -p{scroll_params} | tail -n {height} | {dir}/target/release/thumbs -f '%U:%H' -t {tmp} {args}; tmux swap-pane -t {active_pane_id}; {zoom_command} tmux wait-for -S {signal}", + "tmux capture-pane -et {active_pane_id} -p{scroll_params} | tail -n {height} | {binary} -f '%U:%H' -t {tmp} {args}; tmux swap-pane -t {active_pane_id}; {zoom_command} tmux wait-for -S {signal}", active_pane_id = active_pane_id, scroll_params = scroll_params, height = self.active_pane_height.unwrap_or(i32::MAX), - dir = self.dir, + binary = binary, tmp = TMP_FILE, args = args.join(" "), zoom_command = zoom_command, diff --git a/tmux-thumbs.sh b/tmux-thumbs.sh index 92d5625..b652d7d 100755 --- a/tmux-thumbs.sh +++ b/tmux-thumbs.sh @@ -35,4 +35,4 @@ add-param command string add-param upcase-command string add-param osc52 boolean -"${CURRENT_DIR}/target/release/tmux-thumbs" "${PARAMS[@]}" || true +"$TMUX_THUMBS_BINARY" "${PARAMS[@]}" diff --git a/tmux-thumbs.tmux b/tmux-thumbs.tmux index 4fc9355..6edf1dd 100755 --- a/tmux-thumbs.tmux +++ b/tmux-thumbs.tmux @@ -7,10 +7,4 @@ DEFAULT_THUMBS_KEY=space THUMBS_KEY="$(tmux show-option -gqv @thumbs-key)" THUMBS_KEY=${THUMBS_KEY:-$DEFAULT_THUMBS_KEY} -tmux bind-key "${THUMBS_KEY}" run-shell -b "${CURRENT_DIR}/tmux-thumbs.sh" - -BINARY="${CURRENT_DIR}/target/release/thumbs" - -if [ ! -f "$BINARY" ]; then - tmux split-window "cd ${CURRENT_DIR} && cargo build --release --target-dir=target && echo 'Press any key to continue...' && read -k1" -fi +tmux bind-key "${THUMBS_KEY}" run-shell -b "TMUX_THUMBS_BINARY=$HOME/.cache/cargo/bin/tmux-thumbs ${CURRENT_DIR}/tmux-thumbs.sh"