mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 19:45: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
|
# 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
|
# your shell commands (as well as your shell history with <CTRL-R>).
|
||||||
# with a list of branches to choose from.
|
# E.g. typing `git checkout <CTRL-T>` will open television with a list of
|
||||||
|
# branches to choose from.
|
||||||
|
|
||||||
[shell_integration.commands]
|
[shell_integration.commands]
|
||||||
# Add your commands here. Each key is a command that will trigger tv with the
|
# 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"
|
# "cat" = "files"
|
||||||
# ```
|
# ```
|
||||||
|
|
||||||
# shell history (according to your shell)
|
|
||||||
"" = "zsh-history"
|
|
||||||
|
|
||||||
# environment variables
|
# environment variables
|
||||||
"export" = "env"
|
"export" = "env"
|
||||||
"unset" = "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_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> {
|
pub fn completion_script(shell: Shell) -> Result<&'static str> {
|
||||||
match shell {
|
match shell {
|
||||||
|
Shell::Bash => Ok(COMPLETION_BASH),
|
||||||
Shell::Zsh => Ok(COMPLETION_ZSH),
|
Shell::Zsh => Ok(COMPLETION_ZSH),
|
||||||
_ => color_eyre::eyre::bail!(
|
_ => color_eyre::eyre::bail!(
|
||||||
"This shell is not yet supported: {:?}",
|
"This shell is not yet supported: {:?}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user