Replies: 2 comments
-
I keep all my aliases in multiple files in the $XDG_CONFIG_HOME/zsh/aliases directory the function searches all my aliases and displays them on the left
dependencies needed
zsh function ae to display my aliases#!bin/zsh
#filename of this is ae
export _fzf_home_alias_dir="$XDG_CONFIG_HOME/zsh/aliases"
_fzf_home_getAliases(){
# match alias aliasName='blah'
# match alias -g aliasName='blah'
# match alias -g aliasName="blah"
# \x1b is an escape code
rg \
--follow \
--color always \
--field-context-separator '' \
--no-context-separator \
-e "(^alias)(\s*)(-g)?(\s*)(?P<aliasName>(.*))(=)" -r '$aliasName ' \
--field-match-separator ' ' \
$_fzf_home_alias_dir \
-g '!**/archive/*' \
| gsed "s!$_fzf_home_alias_dir!!" \
| gsed -E 's!(#)(\s*)!\1 !' \
| gsed -E "s/#.*/"$'\x1b[38;2;82;96;255m'"&"$'\e[m'"/"
}
function ae(){
# search home functions
local result=$(
_fzf_home_getAliases | fzf --ansi \
--preview="fzf_home_alias_preview {1} {2}" \
--bind "enter:execute(fzf_home_alias_edit {1} {2} < /dev/tty > /dev/tty 2>&1)+abort"
)
}
ae script fzf_home_alias_previewthis script provides the right hand preview of the file in the screenshot #!/bin/zsh
# filename is fzf_home_alias_preview
# fzf_home_alias_preview <inputFile> <inputAlias>
# search for <inputAlias> in <inputFile>, find line number of inputAlias and provide to fzf-bat-preview
# needs to match
# alias test='test alias'
# alias test="test alias"
# alias -g test="test alias"
# alias -g test="test alias" # comments
local inputFile=$1
local inputAlias=$2
local aliasLineNumber
local file=$_fzf_home_alias_dir$inputFile
rg --only-matching --multiline --line-number --with-filename \
-e "^alias(\s*)(-g)?(\s*)$inputAlias" $file \
| rg '(?::)(\d+)(?::)' --only-matching --replace '$1' \
| read -r aliasLineNumber _
fzf-bat-preview $_fzf_home_alias_dir$inputFile $aliasLineNumber script fzf-bat-preview to preview selected alias file with batcenters the preview on the selected alias
script to edit with nvim if i press enter#!/bin/zsh
# filename is fzf_home_alias_edit
local inputFile=$1
local inputAlias=$2
cache=$XDG_STATE_HOME/dir-switcher/cache # store MRU files for each directory here
local file=$_fzf_home_alias_dir$inputFile
rg --only-matching --multiline --line-number --with-filename \
-e "^alias(\s*)(-g)?(\s*)$inputAlias" $file \
| rg '(?::)(\d+)(?::)' --only-matching --replace '$1' \
| read -r aliasLineNumber _
# center the screen after opening the alias text file with nvim
nvim $file +$aliasLineNumber -c 'normal! zz' |
Beta Was this translation helpful? Give feedback.
0 replies
-
hey man I used not sure if that helps you: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there, I am trying to add descriptions to search results in the terminal similar to how it works when autocompleting git commands, for example:
Specifically, I'd like add descriptions to some of the less frequently used git aliases that I have so I can quickly remember what they do without having to open the aliases file to see what they map to.
I did try to search for answers but couldn't find much (searching for "descriptions" in the Q&A category returns 0 results), and I couldn't find anything mentioning this in the docs. But seeing that it works for the git commands for example then I imagine it should be doable for other commands as well no?
Beta Was this translation helpful? Give feedback.
All reactions