Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make .bashrc aliases available within a vim shell command? (:!...)

Tags:

alias

bash

vim

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?

like image 394
Nick Vanderbilt Avatar asked Jan 10 '11 00:01

Nick Vanderbilt


People also ask

How do I show my aliases in my shell?

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.

Can aliases be used within bash shell scripts?

'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.

What is the command to list aliases?

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.


1 Answers

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/.

like image 144
Josh Lee Avatar answered Oct 19 '22 06:10

Josh Lee