Project TODOs.
- Refactor
./install.sh
to work with fish and omf - Setup https://github.com/bashup/.devkit
- Replace
customs/git/local.gitconfig
bygit/config
- Refactor
./make_links.sh
to show what todo, but don't run, but will work with aeval
- bash/zsh
- Fix oh-my-zsh setup
- Enable starship
- Use Scripts to Rule Them All pattern to scripts. Examples:
- Try to customize
$fisher_path
- Make sure the directory
~/.ssh/sockets
is created
# install Xcode cli tools
xcode-select --install
# if --install don't work, reset the cli path and try again
# sudo xcode-select --reset
# install brew from https://brew.sh/
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install new terminal
brew install --cask iterm2
On MacOS the buid-in bash is very outdated, so update and change the default bash.
brew install --bash --bash-completion
bash
# You need to start a new session to use the new bash
macOS 13.5.2 (22G91) has
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)
The latest versions wasGNU bash, version 5.2.15(1)-release (aarch64-apple-darwin22.1.0)
Clone the repository
export DOTFILES_DIR=~/dotfiles
git clone https://github.com/gullitmiranda/dotfiles "$DOTFILES_DIR"
cd "$DOTFILES_DIR"
Create default synlinks:
./make_links.sh
Bundle brew dependencies (brew, cask and mas)
# install brew core packages
brew bundle --file=Brewfile --verbose
TROUBLESHOOTING: If you receive the error
Error: It seems there is already an App at ...
, manually install the package with--force
and try again.
mas
is a Mac App Store command-line interfac
Install shell integration - https://iterm2.com/documentation-shell-integration.html
# bash
curl -L https://iterm2.com/shell_integration/bash -o ~/.iterm2_shell_integration.bash
# fish
curl -L https://iterm2.com/shell_integration/fish -o ~/.iterm2_shell_integration.fish
# zsh
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh
dotfiles already load iterm2 shell integrations if the file
$HOME/.iterm2_shell_integration.$SHELL
is found
NOTE: fish is installed on
brew bundle
command
Install omf
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish
Install fisher and plugins
# Install fisher cli
echo "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source; and fisher install jorgebucaran/fisher" | fish
# Force fisher plugins install:
fisher list | fisher install
To set Fish as the default shell on iTerm2, follow these steps:
-
Install Fish shell if you haven't already. You can download it from the official website or use a package manager like Homebrew.
-
Open iTerm2.
-
Go to the "iTerm2" menu and select "Preferences" or press
⌘
+,
. -
In the Preferences window, click on the "Profiles" tab.
-
Select the profile you want to use Fish as the default shell for or create a new profile.
-
In the "Command" section, select the option "Custom Shell" and enter
/usr/local/bin/fish
or/opt/homebrew/bin/brew
(on MacOS M1/M2) as the command. Note that the path might be different depending on your Fish shell installation location. -
Click "OK" to save the profile.
-
Open a new iTerm2 tab for the changes to take effect.
Now, whenever you open iTerm2 or create a new tab, Fish shell will be used as the default shell for that profile.
Follow the instructions from https://gist.github.com/plembo/2a116930d107a6745f239be9e453953c
- Cursor (alternative to vscode)
When working with Cursor.so, don't forget to override the code
command to open the cursor app.
# Override the code command to open cursor
ln -fs /Applications/Cursor.app/Contents/Resources/app/bin/code /usr/local/bin/code
This will ensure that the code
command opens the Cursor app instead of VSCode, and also configure shell integration for Cursor. More info at https://code.visualstudio.com/docs/terminal/shell-integration#_manual-installation
Set fish as default shell https://fishshell.com/docs/current/index.html#default-shell
which fish | sudo tee -a /etc/shells
chsh -s $(which fish)
# to revert to bash
which bash | sudo tee -a /etc/shells
chsh -s $(which bash)
Install dependencies
mise install
First, ensure the 1Password CLI is installed and configured https://support.1password.com/command-line-getting-started/
brew install 1password-cli
To turn on the 1Password SSH agent
on 1Password App, access Settings > Developer
enable the option Use the SSH agent
and Integrate with 1Password CLI
(Optional) Make the agent socket easier to access:
mkdir -p ~/.ssh/sockets
ln -s ~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock ~/.ssh/sockets/1password-agent.sock
Change the SSH client to use the 1Password agent
mkdir -p ~/.ssh
# configure the SSH client
cat <<EOF | tee -a ~/.ssh/config
Host *
IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
EOF
# or you can also set the SSH_AUTH_SOCK environment variable
export SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
Create a local git config file from the sample. This will make sure that custom configs (probably with sensitive data) aren't commited
cp .config/git/sample.local.gitconfig ~/.gitconfig
Set your user name and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
How to check if all git config files are loaded
git config --show-origin --get-regexp '(user|gpg|ssh|commit|credential|include)'
First you need to setup the 1password SSH agent.
download ssh public keys from 1password into ~/.ssh/
# list all ssh keys
op item list --categories "SSH Key"
ID TITLE VAULT EDITED
0000004JFGSYAKHH7NVQ9G4B47 GitHub SSH Key Work Work 10 months ago
0000004JFGSYAKHH7NVQ9G4B48 GitHub SSH Key Personal Personal 1 year ago
# download the ssh public key
op read "op://Work/GitHub SSH Key Work/public key" --out-file ~/.ssh/op_Work.pub
op read "op://Personal/GitHub SSH Key Personal/public key" --out-file ~/.ssh/op_Personal.pub
# set the permissions
chmod 600 ~/.ssh/op_*.pub
Configure git to rewrite the ssh url to use the 1password agent
git config --global url."git@github.Work:Work/".insteadOf "https://github.com/Work/"
git config --global url."git@github.com:".insteadOf "https://github.com/"
Configure SSH hosts
cat <<EOF | tee -a ~/.ssh/config
# Work GitHub
Host github.Work
HostName github.com
User git
# this only works with the 1password agent
IdentityFile ~/.ssh/op_Work.pub
IdentitiesOnly yes
# Personal GitHub
Host github.com
HostName github.com
User git
# this only works with the 1password agent
IdentityFile ~/.ssh/op_Personal.pub
IdentitiesOnly yes
EOF
To create a Personal Access Token following the instructions from your provider:
- Follow this link to create a Personal Access Token on GitHub: https://github.com/settings/tokens/new?description=git-credential-1password&expires_in=7776000&scopes=repo,public_repo.
- Fill in the required information and click 'Generate token'.
- Import the token into 1password
Once you leave or refresh the page, you won't be able to access it again. How to use 1password browser extension to auto import the PAT: https://developer.1password.com/docs/cli/shell-plugins/github/#step-1-create-and-save-a-github-personal-access-token
- Follow this link to create a Personal Access Token on GitLab: https://gitlab.com/-/profile/personal_access_tokens.
- Fill in the required information
- scopes:
read_repository, write_repository
- scopes:
- Click 'Create personal access token'
- Import the token into 1password
Once you leave or refresh the page, you won't be able to access it again.
You can import the Personal Access Token into 1Password using one of the options bellow:
- Open 1Password.
- Click on the '+' button to create a new item.
- Choose 'Password' as the type.
- Fill in the details, pasting your Personal Access Token into the 'password' field.
- Save the new item.
op item create \
--category=Password \
--title='GitHub PAT git-credential-1password' \
password[password]='<Your GitHub PAT>'
This item will be saved into default vault. Run
op item create --help
for more info.
Configure Git to use the git-credential-1password
script as the credential helper
git config --global credential.helper "git-credential-1password 'op://Personal/GitHub PAT git-credential-1password/password'"
git config --global credential.useHttpPath true
# expected .gitconfig
[credential]
helper = git-credential-1password "op://Personal/GitHub PAT git-credential-1password/password"
useHttpPath = true
Replace
op://Personal/GitHub PAT git-credential-1password/password
with the name of the 1Password item that contains your personal access token. More info at https://developer.1password.com/docs/cli/secret-references
To use multiple accounts on one server (e.g. github) you can force git to put the username on the URL.
git config --global url."https://username@github.com/".insteadOf "https://github.com/"
# with store --file
echo "https://x-access-token:$GHA_PAT@github.com" > ~/Code/Org/.git-credentials && \
git config --global credential.helper 'store --file ~/Code/Org/.git-credentials'
-
-
You can get all required configs from "1Password SSH key" > "..." > "Configure Commit Signing..."
-
Save the config on
~/Code/$ORG/.gitconfig
. ex:pbpaste > ~/Code/$ORG/.gitconfig
-
Configure git to only use this signin config on repositories from
~/Code/$ORG
git config --global includeIf.gitdir:~/Code/$ORG/.path ~/Code/$ORG/.gitconfig
-
-
Check the configs:
git config --show-origin --get-regexp '(user|gpg|ssh|commit|credential|include)'
References:
References to try:
From the update-macos-via-cli-with-softwareupdate use the command softwareupdate -ia.
softwareupdate -ia
From the manage-mac-appstore-apps-with-mas include the command mas upgrade.
mas upgrade
Use the brew update, upgrade, and cleanup to install pending updates and upgrades for brew managed apps.
brew update && brew upgrade && brew cleanup
A collection of utils bash and fish scripts
Gets the current working directory
- bash
# bash directory helpers (with pwd duplication prevention)
__CWD="$(dirname "${BASH_SOURCE[0]:-$0}")"
__DIRNAME="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" &>/dev/null && pwd)"
__ROOT="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/../.." &>/dev/null && pwd)"
__RELATIVE="$(echo $__DIRNAME | sed -e "s#$__ROOT/##g")"
- fish
# Gets the current working directory
set __DIRNAME (realpath (dirname (status filename)))