Pane swaping working

This commit is contained in:
Ferran Basora 2019-03-05 08:10:41 +00:00
parent cabbac442a
commit cd348adc18
2 changed files with 23 additions and 2 deletions

View File

@ -61,6 +61,10 @@ fn app_args<'a> () -> clap::ArgMatches<'a> {
.long("position")
.default_value("left")
.short("p"))
.arg(Arg::with_name("tmux_pane")
.help("Get this tmux pane as reference pane")
.long("tmux-pane")
.takes_value(true))
.arg(Arg::with_name("command")
.help("Pick command")
.long("command")
@ -87,8 +91,13 @@ fn main() {
let command = args.value_of("command").unwrap();
let upcase_command = args.value_of("upcase_command").unwrap();
let tmux_subcommand = if let Some(pane) = args.value_of("tmux_pane") {
format!(" -t {}", pane)
} else {
"".to_string()
};
let execution = exec_command(format!("tmux capture-pane -e -J -p"));
let execution = exec_command(format!("tmux capture-pane -e -J -p{}", tmux_subcommand));
let output = String::from_utf8_lossy(&execution.stdout);
let lines = output.split("\n").collect::<Vec<&str>>();
@ -110,6 +119,11 @@ fn main() {
viewbox.present()
};
if let Some(pane) = args.value_of("tmux_pane") {
exec_command(format!("tmux swap-pane -t {}", pane));
};
if let Some((text, paste)) = selected {
exec_command(str::replace(command, "{}", text.as_str()));

View File

@ -1,3 +1,10 @@
#!/usr/bin/env bash
/home/ubuntu/dev/tmux-thumbs/target/release/tmux-thumbs -a qwerty -r -u
CURRENT_PANE_ID=$(tmux list-panes -F "#{pane_id}:#{?pane_active,active,nope}" | grep active | cut -d: -f1)
COMMAND="/home/ubuntu/dev/tmux-thumbs/target/debug/tmux-thumbs -a qwerty -r -u --tmux-pane ${CURRENT_PANE_ID}"
tmux new-window -d -n "[thumbs]" ${COMMAND}
NEW_PANE_ID=$(tmux list-panes -a | grep 0:3.1 | grep -o '%[0-9]\+')
tmux swap-pane -t ${NEW_PANE_ID}