mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 03:25:23 +00:00
feat(shell): add bash support for smart autocomplete and shell history (#184)
Fixes #180
This commit is contained in:
parent
0b5facca6a
commit
7614fbc653
@ -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 <CTRL-T>` will open television
|
||||
# with a list of branches to choose from.
|
||||
# your shell commands (as well as your shell history with <CTRL-R>).
|
||||
# E.g. typing `git checkout <CTRL-T>` 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"
|
||||
|
24
crates/television-utils/shell/completion.bash
Normal file
24
crates/television-utils/shell/completion.bash
Normal file
@ -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'
|
@ -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: {:?}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user