Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Last active July 9, 2024 18:13
Show Gist options
  • Save igoralves1/56d1bef8cfe9c6bc100ab2c100d3a0ed to your computer and use it in GitHub Desktop.
Save igoralves1/56d1bef8cfe9c6bc100ab2c100d3a0ed to your computer and use it in GitHub Desktop.
Setup .bash_profile in a MAC AND .bashrc in Ubuntu
# Para computadores MAC
# 1-Criar um arquivo `.bash_profile` se ele nao existir:
# 1.0 - Ir para `cd /Users/ialves/` e verificar se `.bash_profile` existe dentro desse folder `ls -a`
# 1.1 - Se não existir criar o arquivo `.bash_profile`: `touch .bash_profile`. Nota: o arquivo foi criado em `/Users/ialves/` mas ele pode ser acessado em `~/`
# 1.2 - Ir para Finder > Go > HD > Users > ialves e procurar o arquivo `.bash_profile`. Arrastar para a APP VsCode.
# 1.3 - Usar o seguinte código dentro do arquivo `.bash_profile`:
# 1.4 - From https://brew.sh/ run the following: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" . This will install brew.
# 1.5 - After Brew installation run: echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile and then you will have this: eval "$(/opt/homebrew/bin/brew shellenv)" in your .bash_profile
#. 1.6 - Run: source ~/.bash_profile to restart the bash. Chech if brew is installed and running by the command: brew.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
alias ~="cd ~"
alias vh="clear && cd ~/Documents/vhosts/"
alias vhl="clear && cd ~/Documents/vhosts/ && ll"
alias ll="clear && ls -alF"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
eval "$(/opt/homebrew/bin/brew shellenv)"
# 1.4 - Reinicializar o `.bash_profile`: `source ~/.bash_profile`
# 2-Ir em Terminal > preferences > General > Shells Open with `/bin/bash`. Make it sure that it points to `/bin/bash`.
# Other options could be `/bin/zsh` or `/bin/ksh` or `/bin/tcsh` or `/bin/bash`
# or `/bin/sh` ===>
# Notes:
# https://osxdaily.com/2012/03/21/change-shell-mac-os-x/
# https://stackoverflow.com/questions/8967843/how-do-i-create-a-bash-alias
# https://stackoverflow.com/questions/30461201/how-do-i-edit-path-bash-profile-on-osx
# FOR NVM - Reference on SLACK
# https://igoralves1workspace.slack.com/archives/C019FL59JLQ/p1637772008000400
# VS CODE after a new instalation:
> Open vcCode from terminal with the `code .` command.
```
~$ code .
-bash: code: command not found
```
Install Shell Command:
- In the top menu, click on “View” and select “Command Palette” or use the keyboard shortcut (Cmd+Shift+P).
- In the command palette, type "Shell Command" and select "Shell Command: Install 'code' command in PATH."
- It is done. Now 'code' command is saved in PATH. Just test. Run: `code .`
[“code .” Not working in Command-Line for Visual Studio Code on OSX/Mac](https://therealprogrammer.com/code-not-working-in-command-line-for-visual-studio-code-on-osx-mac/)
> Make sure you drag the Visual Studio Code app into the -Applications- folder
Otherwise (as noted in the comments) you’ll have to go through this process again after the reboot
>Next, open Visual Studio Code; Open the Command Palette via (⇧⌘P) and type shell command to find the `Shell Command: Install code command in path`
>Update: use Uninstall ‘code’ command in PATH** command before
# Para computadores Linux/Ubuntu - Setup `bashrc`
# At the end of this process you will have a colored shell with the git branch name.
1-Go to ~/ directory, or /home/"username";
2-`$ sudo code .bashrc`
3-Put this function in the .bashrc:
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
5-Find this portion of the code:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
6-And change for this:
if [ "$color_prompt" = yes ]; then
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' #Igor put in comment
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' #Igor added this line
else
#PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' #Igor put in comment
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ ' #Igor added this line
fi
unset color_prompt force_color_prompt
https://www.leaseweb.com/labs/2013/08/git-tip-show-your-branch-name-on-the-linux-prompt/
========
Set some alias:
alias ll='ls -al'
alias vh='clear && cd ~/Documents/vhosts/ && ll'
alias ~='cd ~'
alias fwBreakdown_node_ec2='ssh -i "/Users/ialves/Documents/ec2_access_scican.pem" ubuntu@ec2-54-209-138-210.compute-1.amazonaws.com'
# Reload .bashrc settings without logging out and back in again
$ source ~/.bashrc
or
$ . ~/.bashrc
# https://stackoverflow.com/questions/2518127/how-to-reload-bashrc-settings-without-logging-out-and-back-in-again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment