mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Start argv[0] with a hyphen in login shell check
Since Rust 1.45 just came out today.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::os::unix::process::CommandExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use textwrap::Wrapper;
|
use textwrap::Wrapper;
|
||||||
@@ -30,12 +31,6 @@ use textwrap::Wrapper;
|
|||||||
///
|
///
|
||||||
/// When we could not find `yabridge-host.exe`, we'll return `Err(shell_name)` so we can print a
|
/// When we could not find `yabridge-host.exe`, we'll return `Err(shell_name)` so we can print a
|
||||||
/// descriptive warning message.
|
/// descriptive warning message.
|
||||||
///
|
|
||||||
/// # TODO
|
|
||||||
///
|
|
||||||
/// Starting from Rust 1.45 we can just modify `argv[0]` to start with a dash instead, see
|
|
||||||
/// https://doc.rust-lang.org/std/os/unix/process/trait.CommandExt.html#tymethod.arg0
|
|
||||||
/// https://github.com/rust-lang/rust/issues/66510
|
|
||||||
pub fn verify_path_setup() -> Result<(), String> {
|
pub fn verify_path_setup() -> Result<(), String> {
|
||||||
match env::var("SHELL") {
|
match env::var("SHELL") {
|
||||||
Ok(shell_path) => {
|
Ok(shell_path) => {
|
||||||
@@ -45,7 +40,13 @@ pub fn verify_path_setup() -> Result<(), String> {
|
|||||||
.and_then(|os_str| os_str.to_str())
|
.and_then(|os_str| os_str.to_str())
|
||||||
.unwrap_or_else(|| shell_path.as_str());
|
.unwrap_or_else(|| shell_path.as_str());
|
||||||
|
|
||||||
|
// We're using the `-l` flag present in most shells to start a login shell, but some
|
||||||
|
// shells don't have this option. According the Bash's man page, another method some
|
||||||
|
// shells use to determine that they're being run as a login shell is by checking that
|
||||||
|
// `argv[0]` starts with a hyphen, so we'll also do that.
|
||||||
let mut command = Command::new(&shell_path);
|
let mut command = Command::new(&shell_path);
|
||||||
|
command.arg0(format!("-{}", &shell_path));
|
||||||
|
|
||||||
let command = match shell {
|
let command = match shell {
|
||||||
// All of these shells support the `-l` flag to start a login shell and have a
|
// All of these shells support the `-l` flag to start a login shell and have a
|
||||||
// POSIX-compatible `command` builtin
|
// POSIX-compatible `command` builtin
|
||||||
|
|||||||
Reference in New Issue
Block a user