Skip to content

Commit

Permalink
Prevent precocious abortion of url::open and clipboard copy (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Apr 16, 2020
1 parent 17b9987 commit d7d3321
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ echo -n "$x" | _copy"#,
.as_str(),
)
.spawn()
.map_err(|e| BashSpawnError::new(cmd, e))?;
.map_err(|e| BashSpawnError::new(cmd, e))?
.wait()?;

Ok(())
}
28 changes: 25 additions & 3 deletions src/flows/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,37 @@ pub fn main(func: String, args: Vec<String>) -> Result<(), Error> {
.into_iter()
.next()
.ok_or_else(|| anyhow!("No URL specified"))?;
let code = r#"
exst() {
type "$1" &>/dev/null
}
_open_url() {
local -r url="$1"
if exst xdg-open; then
xdg-open "$url" &disown
elif exst open; then
echo "$url" | xargs -I% open "%"
else
exit 55
fi
}"#;
let cmd = format!(
r#"url="{}"; (xdg-open "$url" 2> /dev/null || open "$url" 2> /dev/null) &disown"#,
url.replace('"', "").replace('\'', "").replace(' ', "+")
r#"{}
read -r -d '' url <<'EOF'
{}
EOF
_open_url "$url""#,
code, url
);
Command::new("bash")
.arg("-c")
.arg(cmd.as_str())
.spawn()
.map_err(|e| BashSpawnError::new(cmd, e))?;
.map_err(|e| BashSpawnError::new(cmd, e))?
.wait()?;
Ok(())
}

Expand Down

0 comments on commit d7d3321

Please sign in to comment.