Skip to content

Commit

Permalink
feat(shell): shell integration support for fish (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpasmantier authored Dec 30, 2024
1 parent 7614fbc commit b49a069
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cable/unix-channels.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'"

22 changes: 22 additions & 0 deletions crates/television-utils/shell/completion.fish
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions crates/television-utils/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b49a069

Please sign in to comment.