diff --git a/base/programs.nix b/base/programs.nix index 2de78f9..57d7f8b 100644 --- a/base/programs.nix +++ b/base/programs.nix @@ -22,6 +22,7 @@ fd ripgrep tree + packages.tmux-thumbs wget # development diff --git a/flake.nix b/flake.nix index c7f0e9f..fb18bcf 100644 --- a/flake.nix +++ b/flake.nix @@ -74,6 +74,10 @@ nixpkgs.overlays = [ emacs-overlay.overlay + (self: super: { + packages = import ./packages { pkgs = super; }; + }) + # uncomment this to build everything from scratch, fun but takes a # while # diff --git a/home/tmux.nix b/home/tmux.nix index 8325fa9..24402eb 100644 --- a/home/tmux.nix +++ b/home/tmux.nix @@ -10,5 +10,6 @@ in config.programs.tmux = lib.mkIf cfg.enable { enable = true; baseIndex = 1; + plugins = with pkgs; [ packages.tmux-thumbs ]; }; } diff --git a/packages/default.nix b/packages/default.nix new file mode 100644 index 0000000..befb57c --- /dev/null +++ b/packages/default.nix @@ -0,0 +1,4 @@ +{ pkgs }: +{ + tmux-thumbs = pkgs.callPackage ./tmux-thumbs.nix {}; +} diff --git a/packages/fix.patch b/packages/fix.patch new file mode 100644 index 0000000..38295c4 --- /dev/null +++ b/packages/fix.patch @@ -0,0 +1,41 @@ +diff --git a/src/swapper.rs b/src/swapper.rs +index aff33e1..cb5f21a 100644 +--- a/src/swapper.rs ++++ b/src/swapper.rs +@@ -210,11 +210,10 @@ impl<'a> Swapper<'a> { + }; + + let pane_command = format!( +- "tmux capture-pane -t {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 -t {active_pane_id} -p{scroll_params} | tail -n {height} | @@replace-me@@/thumbs -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, + tmp = TMP_FILE, + args = args.join(" "), + zoom_command = zoom_command, +diff --git a/tmux-thumbs.sh b/tmux-thumbs.sh +index 92d5625..c6300c7 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 ++@@replace-me@@ "${PARAMS[@]}" || true +diff --git a/tmux-thumbs.tmux b/tmux-thumbs.tmux +index 4fc9355..87c5346 100755 +--- a/tmux-thumbs.tmux ++++ b/tmux-thumbs.tmux +@@ -8,9 +8,3 @@ 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 diff --git a/packages/tmux-thumbs.nix b/packages/tmux-thumbs.nix new file mode 100644 index 0000000..cd69486 --- /dev/null +++ b/packages/tmux-thumbs.nix @@ -0,0 +1,38 @@ +{ pkgs, lib, rustPlatform, fetchFromGitHub }: +let + pname = "tmux-thumbs"; + version = "0.5.1"; + tmux-thumbs-binary = rustPlatform.buildRustPackage { + pname = pname; + version = version; + + src = fetchFromGitHub { + owner = "fcsonline"; + repo = pname; + rev = version; + sha256 = "sha256-rU+tsrYJxoqF8Odh2ucvNekc+fLnSY6kFoVFUjqaTFE="; + }; + + cargoSha256 = "sha256-/F9tftRLqC6dk7lX41C8RUMqlrgzc0nkunc0rue5zuM="; + + patches = [ ./fix.patch ]; + postPatch = '' + substituteInPlace src/swapper.rs --replace '@@replace-me@@' '$out/bin/thumbs' + ''; + meta = {}; + }; +in pkgs.tmuxPlugins.mkTmuxPlugin { + pluginName = pname; + version = version; + rtpFilePath = "tmux-thumbs.tmux"; + src = fetchFromGitHub { + owner = "fcsonline"; + repo = pname; + rev = version; + sha256 = "sha256-rU+tsrYJxoqF8Odh2ucvNekc+fLnSY6kFoVFUjqaTFE="; + }; + patches = [ ./fix.patch ]; + postInstall = '' + substituteInPlace $target/tmux-thumbs.sh --replace '@@replace-me@@' '${tmux-thumbs-binary}/bin/tmux-thumbs' + ''; +}