From 6d26db2993f5a2edc6bc30c6aa36ba66a612573c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 12:48:11 +0000 Subject: [PATCH 1/2] chore(deps): bump tokio from 1.44.1 to 1.44.2 (#453) Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.44.1 to 1.44.2.
Release notes

Sourced from tokio's releases.

Tokio v1.44.2

This release fixes a soundness issue in the broadcast channel. The channel accepts values that are Send but !Sync. Previously, the channel called clone() on these values without synchronizing. This release fixes the channel by synchronizing calls to .clone() (Thanks Austin Bonander for finding and reporting the issue).

Fixed

#7232: tokio-rs/tokio#7232

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tokio&package-manager=cargo&previous-version=1.44.1&new-version=1.44.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/alexpasmantier/television/network/alerts).
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c4670d5..a5347b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2401,9 +2401,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.44.1" +version = "1.44.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a" +checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 8c396db..642c239 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ anyhow = "1.0" base64 = "0.22.1" directories = "6.0" devicons = "0.6" -tokio = { version = "1.43", features = ["full"] } +tokio = { version = "1.44", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } rustc-hash = "2.1" From 4a584b437c413f26c376154fe0751791b9cbd971 Mon Sep 17 00:00:00 2001 From: Alexandre Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Wed, 9 Apr 2025 19:02:58 +0000 Subject: [PATCH 2/2] fix(pwsh): use adequate quoting when formatting preview commands for pwsh (#454) Fixes #382 and #381 ![image](https://github.com/user-attachments/assets/6513cea7-fd42-40e0-8d3b-6bf687f846ca) --- cable/windows-channels.toml | 2 +- television/channels/alias.rs | 30 +++++++----- television/channels/cable.rs | 2 +- television/preview/previewers/command.rs | 2 +- television/utils/command.rs | 28 ++++++----- television/utils/shell.rs | 60 +++++++++++++++++++++++- 6 files changed, 94 insertions(+), 30 deletions(-) diff --git a/cable/windows-channels.toml b/cable/windows-channels.toml index 281df8b..b511080 100644 --- a/cable/windows-channels.toml +++ b/cable/windows-channels.toml @@ -2,7 +2,7 @@ [[cable_channel]] name = "git-diff" source_command = "git diff --name-only" -preview_command = "git diff --color=always {0}" +preview_command = "git diff --color=always -- {0}" [[cable_channel]] name = "git-reflog" diff --git a/television/channels/alias.rs b/television/channels/alias.rs index fed01d0..ecf57da 100644 --- a/television/channels/alias.rs +++ b/television/channels/alias.rs @@ -4,7 +4,9 @@ use crate::channels::entry::Entry; use crate::channels::entry::PreviewType; use crate::channels::OnAir; use crate::matcher::{config::Config, injector::Injector, Matcher}; +use crate::utils::command::shell_command; use crate::utils::indices::sep_name_and_value_indices; +use crate::utils::shell::Shell; use devicons::FileIcon; use rustc_hash::FxBuildHasher; use rustc_hash::FxHashSet; @@ -32,19 +34,20 @@ pub struct Channel { const NUM_THREADS: usize = 1; const FILE_ICON_STR: &str = "nu"; -const SHELL_ENV_VAR: &str = "SHELL"; -fn get_current_shell() -> Option { - std::env::var(SHELL_ENV_VAR).ok() -} +fn get_raw_aliases(shell: Shell) -> Vec { + // this needs to be run in an interactive shell in order to get the aliases + let mut command = shell_command(true); -fn get_raw_aliases(shell: &str) -> Vec { - let output = std::process::Command::new(shell) - .arg("-i") - .arg("-c") - .arg("alias") - .output() - .expect("failed to execute process"); + let output = match shell { + Shell::PowerShell => { + command.arg("Get-Alias | Format-List -Property Name, Definition") + } + Shell::Cmd => command.arg("doskey /macros"), + _ => command.arg("-i").arg("alias").arg("2>/dev/null"), + } + .output() + .expect("failed to execute process"); let aliases = String::from_utf8_lossy(&output.stdout); aliases.lines().map(ToString::to_string).collect() @@ -151,8 +154,7 @@ impl OnAir for Channel { #[allow(clippy::unused_async)] async fn load_aliases(injector: Injector) { - let raw_shell = get_current_shell().unwrap_or("bash".to_string()); - let shell = raw_shell.split('/').last().unwrap(); + let shell = Shell::from_env().unwrap_or_default(); debug!("Current shell: {}", shell); let raw_aliases = get_raw_aliases(shell); @@ -167,6 +169,8 @@ async fn load_aliases(injector: Injector) { value.to_string(), )); } + } else { + debug!("Invalid alias format: {}", alias); } None }) diff --git a/television/channels/cable.rs b/television/channels/cable.rs index 839be19..26ebaf7 100644 --- a/television/channels/cable.rs +++ b/television/channels/cable.rs @@ -110,7 +110,7 @@ impl Channel { #[allow(clippy::unused_async)] async fn load_candidates(command: String, injector: Injector) { debug!("Loading candidates from command: {:?}", command); - let mut child = shell_command() + let mut child = shell_command(false) .arg(command) .stdout(Stdio::piped()) .stderr(Stdio::piped()) diff --git a/television/preview/previewers/command.rs b/television/preview/previewers/command.rs index b239fa7..61894b2 100644 --- a/television/preview/previewers/command.rs +++ b/television/preview/previewers/command.rs @@ -174,7 +174,7 @@ pub fn try_preview( let command = format_command(command, entry, command_re); debug!("Formatted preview command: {:?}", command); - let child = shell_command() + let child = shell_command(false) .arg(&command) .output() .expect("failed to execute process"); diff --git a/television/utils/command.rs b/television/utils/command.rs index 2926bb5..f971ac0 100644 --- a/television/utils/command.rs +++ b/television/utils/command.rs @@ -1,19 +1,21 @@ use std::process::Command; -#[cfg(not(windows))] -pub fn shell_command() -> Command { - let mut cmd = Command::new("sh"); +use super::shell::Shell; - cmd.arg("-c"); - - cmd -} - -#[cfg(windows)] -pub fn shell_command() -> Command { - let mut cmd = Command::new("cmd"); - - cmd.arg("/c"); +pub fn shell_command(interactive: bool) -> Command { + let shell = Shell::from_env().unwrap_or_default(); + let mut cmd = Command::new(shell.executable()); + + cmd.arg(match shell { + Shell::PowerShell => "-Command", + Shell::Cmd => "/C", + _ => "-c", + }); + + #[cfg(unix)] + if interactive { + cmd.arg("-i"); + } cmd } diff --git a/television/utils/shell.rs b/television/utils/shell.rs index 0f9efc3..aa351fa 100644 --- a/television/utils/shell.rs +++ b/television/utils/shell.rs @@ -1,8 +1,10 @@ use crate::cli::args::Shell as CliShell; use crate::config::shell_integration::ShellIntegrationConfig; use anyhow::Result; +use strum::Display; +use tracing::debug; -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Display)] pub enum Shell { Bash, Zsh, @@ -11,6 +13,62 @@ pub enum Shell { Cmd, } +impl Default for Shell { + #[cfg(unix)] + fn default() -> Self { + Shell::Bash + } + + #[cfg(windows)] + fn default() -> Self { + Shell::PowerShell + } +} + +const SHELL_ENV_VAR: &str = "SHELL"; + +impl TryFrom<&str> for Shell { + type Error = anyhow::Error; + + fn try_from(value: &str) -> Result { + if value.contains("bash") { + Ok(Shell::Bash) + } else if value.contains("zsh") { + Ok(Shell::Zsh) + } else if value.contains("fish") { + Ok(Shell::Fish) + } else if value.contains("powershell") { + Ok(Shell::PowerShell) + } else if value.contains("cmd") { + Ok(Shell::Cmd) + } else { + Err(anyhow::anyhow!("Unsupported shell: {}", value)) + } + } +} + +impl Shell { + #[allow(clippy::borrow_interior_mutable_const)] + pub fn from_env() -> Result { + if let Ok(shell) = std::env::var(SHELL_ENV_VAR) { + Shell::try_from(shell.as_str()) + } else { + debug!("Environment variable {} not set", SHELL_ENV_VAR); + Ok(Shell::default()) + } + } + + pub fn executable(&self) -> &'static str { + match self { + Shell::Bash => "bash", + Shell::Zsh => "zsh", + Shell::Fish => "fish", + Shell::PowerShell => "powershell", + Shell::Cmd => "cmd", + } + } +} + impl From for Shell { fn from(val: CliShell) -> Self { match val {