Skip to content

Commit

Permalink
fix: rename function couldn't move to new directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ariakh55 committed Apr 22, 2024
1 parent 56c0b1c commit d48688c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,11 @@ fn sessions_subcommand(tmux: &Tmux) -> Result<(), TmsError> {
fn rename_subcommand(args: &RenameCommand, tmux: &Tmux) -> Result<(), TmsError> {
let new_session_name = &args.name;

let current_session = tmux.display_message("'#S'");
let current_session = current_session.trim();
let current_session = tmux
.display_message("'#S'")
.trim()
.replace('\'', "")
.to_string();

let panes = tmux.list_windows(
"'#{window_index}.#{pane_index},#{pane_current_command},#{pane_current_path}'",
Expand All @@ -476,22 +479,25 @@ fn rename_subcommand(args: &RenameCommand, tmux: &Tmux) -> Result<(), TmsError>
.map(|window| {
let mut _window: Vec<&str> = window.split(',').collect();

let pane_index = _window[0];
let pane_index = _window[0].replace('\'', "");
let pane_details: HashMap<String, String> = HashMap::from([
(String::from("command"), _window[1].to_string()),
(String::from("cwd"), _window[2].to_string()),
(
String::from("cwd"),
_window[2].to_string().replace('\'', ""),
),
]);

paneid_to_pane_deatils.insert(pane_index.to_string(), pane_details);

_window[0].to_string()
pane_index.to_string()
})
.collect();

let first_pane_details = &paneid_to_pane_deatils[all_panes.first().unwrap()];

let new_session_path: String =
String::from(&first_pane_details["cwd"]).replace(current_session, new_session_name);
String::from(&first_pane_details["cwd"]).replace(&current_session, new_session_name);

let move_command_args: Vec<String> =
[first_pane_details["cwd"].clone(), new_session_path.clone()].to_vec();
Expand All @@ -501,9 +507,9 @@ fn rename_subcommand(args: &RenameCommand, tmux: &Tmux) -> Result<(), TmsError>
let pane_details = &paneid_to_pane_deatils[pane_index];

let old_path = &pane_details["cwd"];
let new_path = old_path.replace(current_session, new_session_name);
let new_path = old_path.replace(&current_session, new_session_name);

let change_dir_cmd = format!("\"cd {new_path}\"");
let change_dir_cmd = format!("cd {new_path}");
tmux.send_keys(&change_dir_cmd, Some(pane_index));
}

Expand Down

0 comments on commit d48688c

Please sign in to comment.