packages: package tmux-thumbs

This commit is contained in:
Antoine Martin 2021-04-19 17:09:16 +02:00
parent 7a20e72e86
commit 1ccbe85361
6 changed files with 89 additions and 0 deletions

View file

@ -22,6 +22,7 @@
fd fd
ripgrep ripgrep
tree tree
packages.tmux-thumbs
wget wget
# development # development

View file

@ -74,6 +74,10 @@
nixpkgs.overlays = [ nixpkgs.overlays = [
emacs-overlay.overlay emacs-overlay.overlay
(self: super: {
packages = import ./packages { pkgs = super; };
})
# uncomment this to build everything from scratch, fun but takes a # uncomment this to build everything from scratch, fun but takes a
# while # while
# #

View file

@ -10,5 +10,6 @@ in
config.programs.tmux = lib.mkIf cfg.enable { config.programs.tmux = lib.mkIf cfg.enable {
enable = true; enable = true;
baseIndex = 1; baseIndex = 1;
plugins = with pkgs; [ packages.tmux-thumbs ];
}; };
} }

4
packages/default.nix Normal file
View file

@ -0,0 +1,4 @@
{ pkgs }:
{
tmux-thumbs = pkgs.callPackage ./tmux-thumbs.nix {};
}

41
packages/fix.patch Normal file
View file

@ -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

38
packages/tmux-thumbs.nix Normal file
View file

@ -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'
'';
}