diff --git a/.config/config.toml b/.config/config.toml index 3f39595..122ad87 100644 --- a/.config/config.toml +++ b/.config/config.toml @@ -140,8 +140,9 @@ toggle_preview = "ctrl-o" # ---------------------------------------------------------------------------- # # The shell integration feature allows you to use television as a picker for -# your shell commands. E.g. typing `git checkout ` will open television -# with a list of branches to choose from. +# your shell commands (as well as your shell history with ). +# E.g. typing `git checkout ` will open television with a list of +# branches to choose from. [shell_integration.commands] # Add your commands here. Each key is a command that will trigger tv with the @@ -160,9 +161,6 @@ toggle_preview = "ctrl-o" # "cat" = "files" # ``` -# shell history (according to your shell) -"" = "zsh-history" - # environment variables "export" = "env" "unset" = "env" diff --git a/crates/television-utils/shell/completion.bash b/crates/television-utils/shell/completion.bash new file mode 100644 index 0000000..ef0281f --- /dev/null +++ b/crates/television-utils/shell/completion.bash @@ -0,0 +1,24 @@ +function tv_smart_autocomplete() { + local current_prompt="${READLINE_LINE:0:$READLINE_POINT}" + + local output=$(tv --autocomplete-prompt "$current_prompt") + + if [[ -n $output ]]; then + READLINE_LINE=$current_prompt$output + READLINE_POINT=${#READLINE_LINE} + fi +} + +function tv_shell_history() { + local current_prompt="${READLINE_LINE:0:$READLINE_POINT}" + + local output=$(tv bash-history --input "$current_prompt") + + if [[ -n $output ]]; then + READLINE_LINE=$output + READLINE_POINT=${#READLINE_LINE} + fi +} + +bind -x '"\C-t": tv_smart_autocomplete' +bind -x '"\C-r": tv_shell_history' diff --git a/crates/television-utils/src/shell.rs b/crates/television-utils/src/shell.rs index 692f228..f23e310 100644 --- a/crates/television-utils/src/shell.rs +++ b/crates/television-utils/src/shell.rs @@ -10,9 +10,11 @@ pub enum Shell { } const COMPLETION_ZSH: &str = include_str!("../shell/completion.zsh"); +const COMPLETION_BASH: &str = include_str!("../shell/completion.bash"); pub fn completion_script(shell: Shell) -> Result<&'static str> { match shell { + Shell::Bash => Ok(COMPLETION_BASH), Shell::Zsh => Ok(COMPLETION_ZSH), _ => color_eyre::eyre::bail!( "This shell is not yet supported: {:?}",