From b49a06997b93bc48f9cae2a66acda1e4ccfdb621 Mon Sep 17 00:00:00 2001 From: Alex Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:50:45 +0100 Subject: [PATCH] feat(shell): shell integration support for fish (#186) --- cable/unix-channels.toml | 5 +++++ crates/television-utils/shell/completion.fish | 22 +++++++++++++++++++ crates/television-utils/src/shell.rs | 2 ++ 3 files changed, 29 insertions(+) create mode 100644 crates/television-utils/shell/completion.fish diff --git a/cable/unix-channels.toml b/cable/unix-channels.toml index fc3db41..b4985c1 100644 --- a/cable/unix-channels.toml +++ b/cable/unix-channels.toml @@ -40,3 +40,8 @@ source_command = "tail -r $HOME/.zsh_history | cut -d\";\" -f 2-" [[cable_channel]] name = "bash-history" source_command = "tail -r $HOME/.bash_history" + +[[cable_channel]] +name = "fish-history" +source_command = "fish -c 'history'" + diff --git a/crates/television-utils/shell/completion.fish b/crates/television-utils/shell/completion.fish new file mode 100644 index 0000000..222c727 --- /dev/null +++ b/crates/television-utils/shell/completion.fish @@ -0,0 +1,22 @@ +function tv_smart_autocomplete + set -l current_prompt (commandline -cp) + + set -l output (tv --autocomplete-prompt "$current_prompt") + + if test -n "$output" + commandline -r "$current_prompt$output" + end +end + +function tv_shell_history + set -l current_prompt (commandline -cp) + + set -l output (tv fish-history --input "$current_prompt") + + if test -n "$output" + commandline -r "$output" + end +end + +bind \ct tv_smart_autocomplete +bind \cr tv_shell_history diff --git a/crates/television-utils/src/shell.rs b/crates/television-utils/src/shell.rs index f23e310..faf1911 100644 --- a/crates/television-utils/src/shell.rs +++ b/crates/television-utils/src/shell.rs @@ -11,11 +11,13 @@ pub enum Shell { const COMPLETION_ZSH: &str = include_str!("../shell/completion.zsh"); const COMPLETION_BASH: &str = include_str!("../shell/completion.bash"); +const COMPLETION_FISH: &str = include_str!("../shell/completion.fish"); pub fn completion_script(shell: Shell) -> Result<&'static str> { match shell { Shell::Bash => Ok(COMPLETION_BASH), Shell::Zsh => Ok(COMPLETION_ZSH), + Shell::Fish => Ok(COMPLETION_FISH), _ => color_eyre::eyre::bail!( "This shell is not yet supported: {:?}", shell