Skip to content

Instantly share code, notes, and snippets.

@OleksandrKucherenko
Last active April 22, 2024 07:49
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save OleksandrKucherenko/e76220f22359e0e49c81c5474b1457a1 to your computer and use it in GitHub Desktop.
Save OleksandrKucherenko/e76220f22359e0e49c81c5474b1457a1 to your computer and use it in GitHub Desktop.
Pre-configure My mac
#!/usr/bin/env bash
set -x # uncomment to debug
# required for Homebrew
xcode-select —-install
sudo xcodebuild -license accept
# install https://brew.sh/
which brew || (/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" )
# install latest bash
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
brew install bash
else
echo "[info] detected BASH version: ${BASH_VERSION}"
fi
# Include cask software packages
# Not needed any more, outdated: brew tap caskroom/cask
# install iTerm2
brew install iterm2 --cask
# install ZSH
which zsh || (brew install zsh)
# install latest GIT
brew install git
brew install git-lfs
# install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# ZSH fast-syntax-highlighting
# deprecated: git clone https://github.com/zdharma/fast-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git \
${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting
# ZSH autosuggestions, https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# make ZSH default shell
sudo sh -c "echo $(which zsh) >> /etc/shells" && chsh -s $(which zsh)
# install powerline fonts (https://github.com/powerline/fonts/#quick-installation)
mkdir ~/workspace
git clone https://github.com/powerline/fonts.git --depth=1 ~/workspace/fonts
~/workspace/fonts/install.sh
# show file system as tree in terminal
which tree || (brew install tree)
# `cat` replacer
which bat || (brew install bat)
# expect, simualte user input in scripts
which expect || (brew install expect)
# RIP grep
which rg || (brew install ripgrep)
# https://formulae.brew.sh/formula/midnight-commander
which mcedit || (brew install midnight-commander)
# https://github.com/tldr-pages/tldr
which tldr || (brew install tldr)
# https://formulae.brew.sh/formula/htop
which htop || (brew install htop)
# https://formulae.brew.sh/formula/tmux
which tmux || (brew install tmux)
# JSON, https://formulae.brew.sh/formula/jq
which jq || (brew install jq)
# Yaml, https://github.com/mikefarah/yq
which yq || (brew install yq)
# Nano editor, https://www.nano-editor.org/
which nano || (brew install nano)
# https://formulae.brew.sh/formula/watchman
which watchman || (brew install watchman)
# https://formulae.brew.sh/formula/watch, https://www.geeksforgeeks.org/watch-command-in-linux-with-examples/
which watch || (brew install watch)
# PipeViewer, https://www.ivarch.com/programs/pv.shtml
which pv || (brew install pv)
# Gnu-Sed, https://www.gnu.org/software/sed/
which gsed || (brew install gsed)
# https://command-not-found.com/whiptail
brew install newt
# instal NVM
which nvm || (curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash)
nvm install --lts
nvm use --lts
# install YVM
#which yvm || (brew install tophat/bar/yvm)
which yvm || (curl -s https://raw.githubusercontent.com/tophat/yvm/master/scripts/install.js | node)
yvm list-remote
# install direnv
which direnv || (curl -sfL https://direnv.net/install.sh | bash)
direnv allow
# install RVM, https://rvm.io/rvm/install
which rvm || (curl -sSL https://get.rvm.io | bash -s stable --ruby)
# install LastPass
brew install lastpass --cask
# diff tools
brew install p4v --cask
# p4merge, as GIT default merge tool... https://gist.github.com/tony4d/3454372
git config --global merge.tool p4mergetool
git config --global mergetool.p4mergetool.cmd "/Applications/p4merge.app/Contents/Resources/launchp4merge \$PWD/\$BASE \$PWD/\$REMOTE \$PWD/\$LOCAL \$PWD/\$MERGED"
git config --global mergetool.p4mergetool.trustExitCode false
git config --global mergetool.keepBackup false
#brew install kdiff3
# GIT UI
brew install fork --cask
# install messangers
brew install --cask slack
brew install --cask zoom
brew install --cask telegram-desktop
brew install --cask skype
brew install --cask microsoft-teams
brew install --cask discord
# install alternative browser
brew install google-chrome --cask
# Extensions:
# LastPass: https://chrome.google.com/webstore/detail/lastpass-free-password-ma/hdokiejnpimakedhajhdlcegeplioahd?hl=en-GB
# LanguageTool: https://chrome.google.com/webstore/detail/grammar-and-spell-checker/oldceeleldhonbafppcapldpdifcinji?hl=en-GB
# Grammarly: https://chrome.google.com/webstore/detail/grammarly-for-chrome/kbfnbcaeplbcioakkpcpgfkobkghlhen?hl=en-GB
# ImTranslator: https://chrome.google.com/webstore/detail/imtranslator-translator-d/noaijdpnepcgjemiklgfkcfbkokogabh?hl=en-GB
# AdsBlock: https://getadblock.com/
brew install firefox --cask
/Applications/Firefox.app/Contents/MacOS/firefox https://addons.mozilla.org/en-US/firefox/addon/lastpass-password-manager/ &
# https://github.com/AdoptOpenJDK/homebrew-openjdk
# brew tap AdoptOpenJDK/openjdk
# brew install adoptopenjdk11 --cask
brew install --cask temurin
# install extra fonts
brew tap homebrew/cask-fonts
brew install font-fira-code --cask
brew tap colindean/fonts-nonfree
brew install font-microsoft-office --cask
# install vscode
brew install visual-studio-code --cask
# install TextMate, https://formulae.brew.sh/cask/textmate
brew install textmate --cask
# Anydesk, https://formulae.brew.sh/cask/anydesk
brew install anydesk --cask
# cyberduck, https://cyberduck.io/
brew install cyberduck --cask
# XnConvert, https://www.xnview.com/en/xnconvert/
brew install xnconvert --cask
brew install imagemagick
brew install graphicsmagick
brew install ffmpeg
# Clipboard Manager, Multiple Clipboards
# Clipy, https://clipy-app.com/
brew install clipy --cask
# https://maccy.app/, https://github.com/p0deje/Maccy
brew install maccy
# trolCommander, https://trolsoft.ru/en/soft/trolcommander
brew install trolcommander --cask
# Far Manager For Linux (works for MacOs), https://github.com/elfmz/far2l
brew install --cask far2l
# GitUp, https://gitup.co/
brew install gitup --cask
# Kap, https://getkap.co/
brew install kap --cask
# Keka, www.keka.io
brew install keka --cask
# Be Focused, https://xwavesoft.com/be-focused-pro-for-iphone-ipad-mac-os-x.html
# Windows manager
# Magnet, https://magnet.crowdcafe.com/index.html
# Penc, https://deniz.co/penc/
brew install penc --cask
# Divvy, https://mizage.com/divvy/
brew install divvy --cask
# Calendar, Time, https://www.mowglii.com/itsycal/
# Use pattern: E | 'w'ww | d MMM, HH:mm:ss
brew install itsycal --cask
# Hex Fiend, https://ridiculousfish.com/hexfiend/, https://formulae.brew.sh/cask/hex-fiend
brew install hex-fiend --cask
# https://github.com/zsh-users/zsh-completions
# Android Logcat
brew install pidcat
# Androic Screen Copy tool, https://formulae.brew.sh/formula/scrcpy
brew instal scrcpy
# Screensaver
# https://fliqlo.com/#/screensaver
brew install fliqlo --cask
# Markdown editor, https://macdown.uranusjr.com/
brew install macdown --cask
# https://objective-see.com/products/knockknock.html
brew install knockknock --cask
# manual actions
echo '
plugins=(git colored-man-pages colorize pip python brew osx fast-syntax-highlighting zsh-autosuggestions)
'
# https://github.com/cnstntn-kndrtv/open-in-buttons-for-finder-toolbar
# Finder: Show hidden files
defaults write com.apple.finder AppleShowAllFiles YES
# Finder: Automatically open a new Finder window when a volume is mounted
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true
# Activity Monitor: Visualize CPU usage in the Activity Monitor Dock icon
defaults write com.apple.ActivityMonitor IconType -int 5
# Temperature monitoring: https://beebom.com/how-check-cpu-temperature-mac/, https://fannywidget.com/
brew install fanny
# Enable TouchID for terminal SUDO
# https://dev.to/equiman/how-to-use-macos-s-touch-id-on-terminal-5fhg
# https://unix.stackexchange.com/questions/99350/how-to-insert-text-before-the-first-line-of-a-file
sudo gsed -i '1i auth sufficient pam_tid.so' /etc/pam.d/sudo
# Configure environment ~/.zshrc
# https://www.appsdeveloperblog.com/how-to-set-java_home-on-mac/
#
# List available: `/usr/libexec/java_home -V`
#
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export ANDROID_HOME=/usr/local/opt/android
export GRADLE_USER_HOME=/usr/local/opt/.gradle
export M2_HOME=/usr/local/opt/.m2
# run in terminal
launchctl setenv JAVA_HOME $JAVA_HOME
launchctl setenv GRADLE_USER_HOME $GRADLE_USER_HOME
launchctl setenv M2_HOME $M2_HOME
launchctl setenv ANDROID_HOME $ANDROID_HOME
# configure Finder, src: https://github.com/mathiasbynens/dotfiles/blob/main/.macos
# Finder: show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Keep folders on top when sorting by name
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# Display full POSIX path as Finder window title
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# Show hidden files
defaults write com.apple.finder AppleShowAllFiles true
# Avoid creating .DS_Store files on network or USB volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Mar 28, 2021

Database IDE:

brew install --cask dbeaver-community

https://dbeaver.io

Supports all popular databases: MySQL, PostgreSQL, SQLite, Oracle, DB2, SQL Server, Sybase, MS Access, Teradata, Firebird, Apache Hive, Phoenix, Presto, etc.

brew install xo/xo/usql

#
# install usql with odbc support
# add xo tap
#
brew tap xo/xo
brew install --with-odbc usql

SQLite

brew install --cask sqlight

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Oct 18, 2021

Terminal Text Editor:

brew install micro

https://github.com/zyedidia/micro

a good alterantive to Nano, McEdit

@OleksandrKucherenko
Copy link
Author

Improve git status performance:

brew install --HEAD watchman
watchman watch ~/src/client-android
brew tap jgavris/rs-git-fsmonitor https://github.com/jgavris/rs-git-fsmonitor.git
brew install rs-git-fsmonitor
git config core.fsmonitor rs-git-fsmonitor
git status # less than 1 second

ref: https://github.blog/2018-04-05-git-217-released/#speeding-up-status-with-watchman
ref2: https://github.com/jgavris/rs-git-fsmonitor
ref3: https://github.com/git/git/blob/v2.16.0/templates/hooks--fsmonitor-watchman.sample
ref4: https://facebook.github.io/watchman/docs/install.html#buildinstall
video: https://youtu.be/USLB1gwl1vA

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Aug 19, 2022

brew install mtr

sudo mtr google.com --show-ips

image

https://formulae.brew.sh/formula/mtr

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Sep 14, 2022

WiFi6 Network performance testing:

brew install iperf3

https://www.tp-link.com/fi/support/faq/2408/

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Sep 16, 2022

https://github.com/FiloSottile/mkcert

brew install mkcert
brew install nss # if you use Firefox
mkcert -install
mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1

ref: https://stackoverflow.com/questions/26663404/webpack-dev-server-running-on-https-web-sockets-secure

@OleksandrKucherenko
Copy link
Author

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Nov 1, 2022

https://github.com/romkatv/powerlevel10k

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Nov 16, 2022

ref: https://medium.com/@ThisIsUpen/how-to-jump-between-words-in-iterm2-3c22eb5a25ef

  1. Click on iTerm2 and open “Preferences”
  2. Click on “Profiles”
  3. Select your profile from the left (in my case “Default”)
  4. Click on “Keys” tab
  5. Click “Key Mappings” tab
  6. Click the “Presets” dropdown and select “Natural Text Editing”

Commands

# list iTerm2 Global keys Mapping
defaults read com.googlecode.iterm2.plist GlobalKeyMap
defaults read-type com.googlecode.iterm2.plist GlobalKeyMap # Dictionary

#
# template
#
defaults write com.googlecode.iterm2.plist GlobalKeyMap -dict-add "Key" "Value"
# defaults write com.apple.mail DraftsViewerAttributes -dict-add "DisplayInThreadedMode" -string "yes"
# defaults write com.googlecode.iterm2.plist GlobalKeyMap -array-add "Key" "Value"
# defaults write com.googlecode.iterm2.plist "orientation" -string "right"
# defaults write com.googlecode.iterm2.plist "expose-animation-duration" -float 0.1

# <value> is one of:
#   <value_rep>
#  -string <string_value>
#   -data <hex_digits>
#   -int[eger] <integer_value>
#   -float  <floating-point_value>
#   -bool[ean] (true | false | yes | no)
#   -date <date_rep>
#   -array <value1> <value2> ...
#   -array-add <value1> <value2> ...
#   -dict <key1> <value1> <key2> <value2> ...
#   -dict-add <key1> <value1> ...

Keys

image

image

Refs:

❯ cat ~/workspace/iterm2-keys-configuration.itermkeymap

{ 
  "Key Mappings":{
    "0x9-0x40000":{"Action":32,"Text":""},
    "0xf72b-0x100000":{"Action":4,"Text":""},
    "0xf703-0x300000-0x7c":{"Version":1,"Action":11,"Text":"0x05","Label":""},
    "0xf702-0x320000":{"Action":33,"Text":""},
    "0xf701-0x300000":{"Action":6,"Text":""},
    "0xf72d-0x100000":{"Action":8,"Text":""},
    "0xf702-0x300000-0x7b":{"Version":1,"Action":11,"Text":"0x01","Label":""},
    "0x7f-0x100000-0x33":{"Version":1,"Action":11,"Text":"0x15","Label":""},
    "0x19-0x60000":{"Action":39,"Text":""},
    "0xf700-0x300000":{"Action":7,"Text":""},
    "0xf703-0x320000":{"Action":34,"Text":""},
    "0xf72c-0x100000":{"Action":9,"Text":""},
    "0xf703-0x280000-0x7c":{"Version":1,"Action":10,"Text":"f","Label":""},
    "0xf729-0x100000":{"Action":5,"Text":""},
    "0x7f-0x80000-0x33":{"Version":1,"Action":11,"Text":"0x17","Label":""},
    "0xf72c-0x20000":{"Action":9,"Text":""},
    "0xf702-0x280000-0x7b":{"Version":1,"Action":10,"Text":"b","Label":""},
    "0xf72d-0x20000":{"Action":8,"Text":""}
  },
  "Touch Bar Items":{}
}

Refs:

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Nov 29, 2022

You could install blueutil and SleepWatcher via homebrew and set a .sleep code to do /usr/local/bin/blueutil -p 0 when going to sleep mode.

To use SleepWatcher, make a shell script in your home directory named .sleep and give it permission with the chmod command.

You also can do a .wake code to turn bluetooth back on with blueutil -p 1

You can find out how to use sleepwatcher here

Refs:

brew install sleepwatcher blueutil
echo "$(which blueutil) -p 0" > ~/.sleep
echo "$(which blueutil) -p 1" > ~/.wakeup
chmod 755 ~/.sleep ~/.wakeup
brew services restart sleepwatcher

Refs:

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Nov 29, 2022

#!/bin/bash

# Start tmux or attach running session
# If you want to end session so that commands do not run in the background,
# you have to press Modifier-C before closing terminal, or individually
# quit each process. Modifier-C usually means Alt-C

# See tmux cheatsheet https://gist.github.com/MohamedAlaa/2961058

# Change to your needs, each project should have unique name
PROJECT="frontend-starter"
COMMAND[0]="npm run serve"
COMMAND[1]="npm run watch-less"
COMMAND[2]="npm run watch-js"

# Don't modify this
_INDEX=0

function run-command {
    tmux send-keys -t "$PROJECT:0.$_INDEX" '' C-m
    tmux send-keys -t "$PROJECT:0.$_INDEX" "$1" C-m

    # Increase the pane counter(or whatever it is??)
    _INDEX=$(($_INDEX + 1))

    # Run splitw for each time but last
    if [ "${#COMMAND[@]}" -ne "$_INDEX" ]; then
        tmux splitw -t $PROJECT:0
    fi

    tmux select-layout -t $PROJECT:0 even-horizontal
}

# Check if tmux session already exists
tmux start-server\; has-session -t $PROJECT 2>/dev/null

if [ "$?" -eq 1 ]; then
    # Session didn't exist so create the session
    TMUX= tmux new-session -d -s $PROJECT -n main

    for cmd in "${COMMAND[@]}"
    do
        echo $cmd
        run-command "$cmd"
    done

    tmux select-pane -t $PROJECT:0.0
    tmux select-window -t 0

    # Add possible configuration here
    # tmux set-option -t $PROJECT mouse-select-pane on
    tmux bind-key -n M-c kill-session
    tmux bind-key -n M-Up    select-pane -U
    tmux bind-key -n M-Down  select-pane -D
    tmux bind-key -n M-Left  select-pane -L
    tmux bind-key -n M-Right select-pane -R
fi

# Kill tmux session on exit
_trap_exit() { tmux kill-session -t $PROJECT; }
trap _trap_exit EXIT


if [ -z "$TMUX" ]; then
    tmux -u attach-session -t $PROJECT
else
    tmux -u switch-client -t $PROJECT
fi

Run multiple processes with output with the use of tmux

Refs:

@OleksandrKucherenko
Copy link
Author

Organize Tray Icons. Hide menu bar icons to give your Mac a cleaner look.

https://github.com/Mortennn/Dozer

brew install --cask dozer

@OleksandrKucherenko
Copy link
Author

https://github.com/dimo414/bkt

Cache long BASH operations

brew install bkt

@OleksandrKucherenko
Copy link
Author

https://apps.apple.com/us/app/otp-manager/id928941247 - OTP Manager (One Time Password) is an apple desktop tool that allows you to get OTP codes not from your phone but from a desktop in-tray app. It can be used for cases when needed two-stage verification in one of the services

@OleksandrKucherenko
Copy link
Author

@OleksandrKucherenko
Copy link
Author

@OleksandrKucherenko
Copy link
Author

Stats of Laptop in Menu Bar

https://github.com/exelban/stats

brew install stats

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Aug 28, 2023

Install from App Store via Command Line command:
https://github.com/mas-cli/mas

brew install mas 

# Amphetamine
mas install 937984704
mas info 937984704
Amphetamine 5.3 [0.0]
By: William Gustafson
Released: 2023-08-24
Minimum OS: 10.14.6
Size: 6,3 MB
From: https://apps.apple.com/se/app/amphetamine/id937984704?mt=12&uo=4

@OleksandrKucherenko
Copy link
Author

https://github.com/moretension/duti

UI: https://github.com/tsonglew/dutis

brew install duti

# get the default app for JPG files
duti -x jpg

# set the default app for bash SH files
duti -s com.microsoft.VSCode .sh all

ref: https://apple.stackexchange.com/questions/91522/change-file-association-in-terminal

@OleksandrKucherenko
Copy link
Author

@OleksandrKucherenko
Copy link
Author

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Nov 2, 2023

https://github.com/liquidaty/zsv

Another good tool for processing CSV, TSV data

src: https://github.com/dbohdan/structured-text-tools

@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Dec 15, 2023

Far Manager For MacOS: https://github.com/elfmz/far2l

brew install --HEAD yurikoles/yurikoles/far2l

keybindings:

create file ~/.config/far2l/settings/key_macros.ini:

[KeyMacros/Shell/Esc]
DisableOutput=0x1
EmptyCommandLine=0x1
Sequence=CtrlO

[KeyMacros/Shell/Bs]
DisableOutput=0x1
EmptyCommandLine=0x1
Sequence=CtrlPgUp

[KeyMacros/Shell/NumEnter]
DisableOutput=0x1
EmptyCommandLine=0x1
Sequence=CtrlPgUp

[KeyMacros/Shell/CtrlNumEnter]
DisableOutput=0x1
EmptyCommandLine=0x1
Sequence=Ins

[KeyMacros/Menu/CtrlBrowserForward]
DisableOutput=0x1
Sequence=Ins

[KeyMacros/Menu/CtrlI]
DisableOutput=0x1
FilePanels=0x1
PluginPanels=0x1
Sequence=Ins

[KeyMacros/Editor/CtrlUp]
DisableOutput=0x1
Sequence=PgUp

[KeyMacros/Editor/CtrlDown]
DisableOutput=0x1
Sequence=PgDn

[KeyMacros/Editor/CtrlS]
DisableOutput=0x1
Sequence=F2

@OleksandrKucherenko
Copy link
Author

BUN

curl -fsSL https://bun.sh/install | bash

@OleksandrKucherenko
Copy link
Author

Refs:

brew install rclone

brew install --cask obsidian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment