Skip to content
This repository was archived by the owner on Dec 22, 2024. It is now read-only.

Commit be30abd

Browse files
committed
Replace homedir with shellexpand
This also gives more flexibility in the commands used (any shell variable now valid) in cmd files.
1 parent e052543 commit be30abd

File tree

4 files changed

+81
-29
lines changed

4 files changed

+81
-29
lines changed

Diff for: Cargo.lock

+56-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ lazy_static = "^1.4"
2222
log = "^0.4"
2323
quit = "^2.0"
2424
rand = "^0.8"
25+
shellexpand = { version = "3.1.0", features = ["full"] }
2526
shlex = "1.1.0"
2627
thiserror = "^1.0"
2728
tmux_interface = { version = "^0.3.1", features = ["tmux_2_8", "cmd_alias"], default-features = false }

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Need to adapt docs from the old [README.org](old/README.org) to here.
4747
- [X] k - kill session
4848
- [X] -n - Open sessions to same hosts as existing session instead of
4949
just attaching to that existing session
50-
- [X] Support same environment variables as shell tm
50+
- [X] Support same environment variables as shell tm (supports any now)
5151
- [X] Simple config files (no ending)
5252
- [X] Allows LIST command, recursively
5353
- [X] Support ++TMREPLACETM++

Diff for: src/main.rs

+23-26
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ use anyhow::{anyhow, Result};
2727
use clap::{Parser, Subcommand};
2828
use directories::UserDirs;
2929
use fehler::{throw, throws};
30-
use home_dir::HomeDirExt;
30+
//use home_dir::HomeDirExt;
3131
use itertools::Itertools;
3232
use rand::distributions::Alphanumeric;
3333
use rand::{thread_rng, Rng};
34+
//use shellexpand::full;
3435
use shlex::Shlex;
3536
use std::{
3637
env,
@@ -688,15 +689,18 @@ impl Session {
688689
if line.contains("new-window") {
689690
tmwin += 1;
690691
}
691-
let modline = line
692-
.replace("SESSION", &self.sesname)
693-
.replace("$HOME", "~/")
694-
.replace("${HOME}", "~/")
695-
.replace("TMWIN", &tmwin.to_string())
696-
.expand_home()?
697-
.into_os_string()
698-
.into_string()
699-
.expect("String convert failed");
692+
let modline = shellexpand::full(
693+
&line
694+
.replace("SESSION", &self.sesname)
695+
.replace("$HOME", "~/")
696+
.replace("${HOME}", "~/")
697+
.replace("TMWIN", &tmwin.to_string()),
698+
)?
699+
.to_string();
700+
// .expand_home()?
701+
// .into_os_string()
702+
// .into_string()
703+
// .expect("String convert failed");
700704
self.targets.push(modline);
701705
}
702706
}
@@ -1189,26 +1193,19 @@ fn parse_line(line: &str, replace: &Option<String>, current_dir: &Path) -> Resul
11891193
// but obviously people may mistype and have a single LIST
11901194
// in a line.
11911195
// Also, ~ and $HOME/${HOME} expansion are supported.
1192-
let cmd: String = cmdparser
1193-
.next()
1194-
.ok_or_else(|| anyhow!("Empty LIST found - no command given"))?
1195-
.replace("$HOME", "~/")
1196-
.replace("${HOME}", "~/")
1197-
.expand_home()?
1198-
.into_os_string()
1199-
.into_string()
1200-
.expect("String convert failed");
1196+
let cmd: String = shellexpand::full(
1197+
&cmdparser
1198+
.next()
1199+
.ok_or_else(|| anyhow!("Empty LIST found - no command given"))?
1200+
.replace("$HOME", "~/")
1201+
.replace("${HOME}", "~/"),
1202+
)?
1203+
.to_string();
12011204
// Next we want the arguments.
12021205
// Also, ~ and $HOME/${HOME} expansion are supported.
12031206
let args: Vec<String> = cmdparser
12041207
.map(|l| l.replace("$HOME", "~/").replace("${HOME}", "~/"))
1205-
.map(|l| {
1206-
l.expand_home()
1207-
.expect("Could not successfully expand ~ for arguments of LIST call")
1208-
.into_os_string()
1209-
.into_string()
1210-
.expect("String convert failed")
1211-
})
1208+
.map(|l| shellexpand::full(&l).expect("Could not expand").to_string())
12121209
.collect();
12131210
debug!("cmd is {}", cmd);
12141211
debug!("args are {:?}", args);

0 commit comments

Comments
 (0)