14

I use numerous aliases set at a given UNIX environment. For example my current fish shell under OSX have these below

  • gm -> git merge
  • dk -> docker kill

and so on.

Now the challenge is I use iTerm 2 for connecting to various remote sessions and I wish these aliases work seamlessly on all sessions.

Is there a way to push these aliases into a global context so that iTerm 2 will input the original command upon detecting these aliases.

i.e if I hit gm + enter in any iTerm window it must issue git merge to the remote session.

7
  • 1
    iTerm 2 has nothing to do with your aliases. These are defined in your .bash_profile. I use iTerm 2 for connecting to various remote sessions - Do you mean you connect to various (meaning different) servers and/or accounts?
    – Allan
    Commented Mar 5, 2018 at 14:03
  • Which shell are you running in iTerm?
    – mmmmmm
    Commented Mar 5, 2018 at 14:18
  • @mark I'm using fish shell in my local. However the servers I connect via ssh won't be having fish shell usually.
    – nehem
    Commented Mar 5, 2018 at 22:32
  • @Allan I agree, but as the #1 terminal app, iTerms can add this as a feature so that it can add the layer of abstraction. There's no point in adding entries bash_profile on numerous servers and keeping them in sync.
    – nehem
    Commented Mar 6, 2018 at 23:18
  • That's not the function of the Terminal and by extension iTerm. The entire idea behind having a profile on a server is so that aliases you create are there regardless of the terminal you attach with. If you want "sync" your profiles, look to rsync.
    – Allan
    Commented Mar 7, 2018 at 0:12

2 Answers 2

16

If you use oh-my-zsh, you will want to place those in ~/.zshrc

vi ~/.zshrc

.
.
.
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias work="cd ~/Lucas/local-sites/"
8
  • 1
    a) OP is using bash and fish not zsh. b) How does this file run on remote servers?
    – mmmmmm
    Commented Mar 28, 2019 at 13:27
  • 1
    Hi @Mark, it's very common for those using iterm2, to use oh-my-zsh, they are a known combo on the mac environment. The title of the question is "Creating aliases in iterm2", not "Creating remote aliases in iterm2", and that's the keywords that generates traffic from Google to this question, so that's what people effectively are searching for. My answer might not answer all questions, but it answers for a considerable percentage of people that end up in this question, so I think it's a valid answer. One of the many possible. Commented Mar 29, 2019 at 13:15
  • 1
    Sounds like we need to edit the title to match the question
    – mmmmmm
    Commented Mar 29, 2019 at 14:53
  • Im using oh-my-zsh, and it works perfectly. Thanks man Commented Jun 7, 2021 at 0:35
  • these doesn't work for ssh sessions Commented Jul 23, 2021 at 12:35
2

Have you tried creating a .bashrc file with these aliases?

It should be created in your home folder ~/.bashrc

4
  • Do you think .bashrc entries will be transported to remote sessions (ssh)? I guess not.
    – nehem
    Commented Mar 5, 2018 at 22:30
  • No you’re right, what I meant was to put them on the remote sessions (if possible)
    – Chris
    Commented Mar 6, 2018 at 15:54
  • For few obvious reasons, I wouldn't do that, 1) The servers I connect occasionally would involve shared account details, which I wouldn't pollute them. 2) The servers I often connect are so dynamic (Ec2 instances) so everytime I need to open vi and edit the .bashrc. Let me know if there are ways to overcome the second one.
    – nehem
    Commented Mar 6, 2018 at 23:15
  • @nehemiah Use a quick script that when creating instances also creates ~/.bash* files. There are may examples - search for dotfiles also see Docker setups which do this - I don't know if ec2 is similar to Docker here.
    – mmmmmm
    Commented Mar 28, 2019 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .