I use bash on mac and one of the aliases is like this
alias gitlog='git --no-pager log -n 20 --pretty=format:%h%x09%an%x09%ad%x09%s --date=short --no-merges'
However when I do
:! gitlog
I get
/bin/bash: gitlog: command not found
I know I can add aliases like this in my .gitconfig
[alias] co = checkout st = status ci = commit br = branch df = diff
However I don't want to add all my bash aliases to .gitconfig. That is not DRY.
Is there a better solution?
To see all your current aliases: You can see that the alias l is a shortcut for the command ls -lg. The first word on each line is the name of the alias; the rest of the line is what gets executed when the alias is used.
'set alias' for any command and the alias command will work fine on the interactive shell, whereas aliasing doesn't work inside the script. Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt.
Linux Alias Syntax[option] : Allows the command to list all current aliases. [name] : Defines the new shortcut that references a command. A name is a user-defined string, excluding special characters and 'alias' and 'unalias', which cannot be used as names.
Bash doesn’t load your .bashrc
unless it’s interactive.
Run :set shellcmdflag=-ic
to set it to interactive for the current session.
To make the setting permanent, add set set shellcmdflag=-ic
to the end of your .vimrc
file.
Use a bang (!
) before sending a command to shell. For example: :! cd folder/
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With