Repository: alexpasmantier/television (language: rust)

Issue:
Builtin channels are used instead of custom channels when executed through the CLI and shell integration
**Description**
Television release [0.9.1](https://github.com/alexpasmantier/television/releases/tag/0.9.1) merged PR #260, to allow custom channels to override builtins. This behavior is not reproducible if Television is launched through the terminal or with shell integration.

**Minimal configuration file excerpts**
  - `$XDG_CONFIG_HOME/television/config.toml`
```toml
[shell_integration.commands]
"ls" = "dirs"
"nvim" = "files"
```

  - `$XDG_CONFIG_HOME/television/custom-channels.toml`
```toml
[[cable_channel]]
name = "dirs"
source_command = "fd -t d -H . $HOME"
preview_command = "lsd -Al1 {}"

[[cable_channel]]
name = "files"
source_command = "fd -t f -H . $HOME"
preview_command = "bat -n --color=always {}"
```

**Video reproducing the issue**
- First example: shows `tv dirs` being executed, then changing to the `dirs` channel through Remote Control. Notice how there's no builtin `dirs` channel listed, yet the preview changes from builtin to `lsd`.
- Second example: `nvim` is completed using shell integration via `zsh`. The builtin files previewer is used, changing to `bat` when the `files` channel is selected via Remote Control.
- Third example: the function `nf`, described below, is executed. It contains a pipe with `tv files` as stdin, which also reproduces the issue listed in the previous example.

https://github.com/user-attachments/assets/71a06b9a-a200-4f03-ba4e-e8611e381ca8

*`nf` function as described in `$ZDOTDIR/.zshrc`*
```sh
function nf() {
  tv files | xargs -ro nvim
}
```

**Expected behavior**
The custom channels with same name as a builtin should be used for all interactions.

**Actual behavior**
Builtin channels are used instead, only being replaced when the custom channel is loaded via Remote Control.

**Environment**
 - OS: Arch Linux, kernel 6.12.9-arch1-1
 - Rust version: N/A
 - Project version: Television 0.9.2, build 1.83.0 (2025-01-10)


Discussion / hints:

Fix patch:
diff --git a/crates/television/cli.rs b/crates/television/cli.rs
index eac206e..9f218b9 100644
--- a/crates/television/cli.rs
+++ b/crates/television/cli.rs
@@ -178,17 +178,19 @@ pub enum ParsedCliChannel {
 
 fn parse_channel(channel: &str) -> Result<ParsedCliChannel> {
     let cable_channels = cable::load_cable_channels().unwrap_or_default();
-    CliTvChannel::try_from(channel)
-        .map(ParsedCliChannel::Builtin)
-        .or_else(|_| {
-            cable_channels
-                .iter()
-                .find(|(k, _)| k.to_lowercase() == channel)
-                .map_or_else(
-                    || Err(eyre!("Unknown channel: {}", channel)),
-                    |(_, v)| Ok(ParsedCliChannel::Cable(v.clone())),
-                )
-        })
+    // try to parse the channel as a cable channel
+    cable_channels
+        .iter()
+        .find(|(k, _)| k.to_lowercase() == channel)
+        .map_or_else(
+            || {
+                // try to parse the channel as a builtin channel
+                CliTvChannel::try_from(channel)
+                    .map(ParsedCliChannel::Builtin)
+                    .map_err(|_| eyre!("Unknown channel: {}", channel))
+            },
+            |(_, v)| Ok(ParsedCliChannel::Cable(v.clone())),
+        )
 }
 
 pub fn list_cable_channels() -> Vec<String> {


Test patch: