Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename function couldn't move to new directory #94

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,11 @@ fn sessions_subcommand(tmux: &Tmux) -> Result<()> {
fn rename_subcommand(args: &RenameCommand, tmux: &Tmux) -> Result<()> {
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 @@ -509,22 +512,25 @@ fn rename_subcommand(args: &RenameCommand, tmux: &Tmux) -> Result<()> {
.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 @@ -534,9 +540,9 @@ fn rename_subcommand(args: &RenameCommand, tmux: &Tmux) -> Result<()> {
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
Loading