├── src
├── vim
│ ├── vim
│ │ ├── backups
│ │ │ └── .gitkeep
│ │ ├── swaps
│ │ │ └── .gitkeep
│ │ ├── undos
│ │ │ └── .gitkeep
│ │ └── snippets
│ │ │ └── emmet.json
│ └── vimrc
├── bin
│ ├── $
│ ├── gzthermal
│ │ ├── macos
│ │ ├── linux-32
│ │ └── linux-64
│ ├── pngthermal
│ │ ├── macos
│ │ ├── linux-32
│ │ └── linux-64
│ └── get-compression-heatmap
├── shell
│ ├── ubuntu
│ │ ├── bash_init
│ │ ├── bash_autocompletion
│ │ ├── bash_colors
│ │ └── bash_aliases
│ ├── bashrc
│ ├── bash_logout
│ ├── bash_init
│ ├── bash_autocompletion
│ ├── macos
│ │ ├── bash_init
│ │ ├── bash_autocompletion
│ │ ├── bash_colors
│ │ └── bash_aliases
│ ├── curlrc
│ ├── bash_aliases
│ ├── inputrc
│ ├── bash_profile
│ ├── bash_options
│ ├── bash_exports
│ ├── bash_prompt
│ └── bash_functions
├── os
│ ├── preferences
│ │ ├── macos
│ │ │ ├── close_system_preferences_panes.applescript
│ │ │ ├── security_and_privacy.sh
│ │ │ ├── firefox.sh
│ │ │ ├── photos.sh
│ │ │ ├── language_and_region.sh
│ │ │ ├── main.sh
│ │ │ ├── maps.sh
│ │ │ ├── textedit.sh
│ │ │ ├── chrome.sh
│ │ │ ├── app_store.sh
│ │ │ ├── terminal.sh
│ │ │ ├── init.sh
│ │ │ ├── trackpad.sh
│ │ │ ├── keyboard.sh
│ │ │ ├── set_terminal_theme.applescript
│ │ │ ├── safari.sh
│ │ │ ├── dock.sh
│ │ │ ├── finder.sh
│ │ │ ├── ui_and_ux.sh
│ │ │ └── Solarized Dark.terminal
│ │ ├── ubuntu
│ │ │ ├── main.sh
│ │ │ ├── privacy.sh
│ │ │ ├── terminal.sh
│ │ │ ├── ui_and_ux.sh
│ │ │ └── set_terminal_theme.sh
│ │ └── main.sh
│ ├── installs
│ │ ├── macos
│ │ │ ├── vim.sh
│ │ │ ├── git.sh
│ │ │ ├── gpg.sh
│ │ │ ├── tmux.sh
│ │ │ ├── compression_tools.sh
│ │ │ ├── video_tools.sh
│ │ │ ├── image_tools.sh
│ │ │ ├── misc.sh
│ │ │ ├── misc_tools.sh
│ │ │ ├── browsers.sh
│ │ │ ├── web_font_tools.sh
│ │ │ ├── main.sh
│ │ │ ├── vscode.sh
│ │ │ ├── bash.sh
│ │ │ ├── utils.sh
│ │ │ ├── xcode.sh
│ │ │ └── homebrew.sh
│ │ ├── ubuntu
│ │ │ ├── vim.sh
│ │ │ ├── cleanup.sh
│ │ │ ├── git.sh
│ │ │ ├── tmux.sh
│ │ │ ├── misc.sh
│ │ │ ├── image_tools.sh
│ │ │ ├── compression_tools.sh
│ │ │ ├── main.sh
│ │ │ ├── build-essentials.sh
│ │ │ ├── misc_tools.sh
│ │ │ └── utils.sh
│ │ ├── main.sh
│ │ ├── npm.sh
│ │ ├── vim.sh
│ │ └── volta.sh
│ ├── restart.sh
│ ├── update_content.sh
│ ├── initialize_git_repository.sh
│ ├── create_local_config_files.sh
│ ├── create_symbolic_links.sh
│ ├── set_github_ssh_key.sh
│ ├── setup.sh
│ └── utils.sh
├── git
│ ├── gitattributes
│ ├── gitignore
│ └── gitconfig
└── tmux
│ └── tmux.conf
├── .markdownlint.json
├── LICENSE.txt
└── README.md
/src/vim/vim/backups/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/vim/vim/swaps/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/vim/vim/undos/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/bin/$:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | $@
4 |
--------------------------------------------------------------------------------
/src/shell/ubuntu/bash_init:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
--------------------------------------------------------------------------------
/src/shell/bashrc:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | [ -n "$PS1" ] \
4 | && . "$HOME/.bash_profile"
5 |
--------------------------------------------------------------------------------
/src/bin/gzthermal/macos:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alrra/dotfiles/HEAD/src/bin/gzthermal/macos
--------------------------------------------------------------------------------
/src/bin/pngthermal/macos:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alrra/dotfiles/HEAD/src/bin/pngthermal/macos
--------------------------------------------------------------------------------
/src/bin/gzthermal/linux-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alrra/dotfiles/HEAD/src/bin/gzthermal/linux-32
--------------------------------------------------------------------------------
/src/bin/gzthermal/linux-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alrra/dotfiles/HEAD/src/bin/gzthermal/linux-64
--------------------------------------------------------------------------------
/src/bin/pngthermal/linux-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alrra/dotfiles/HEAD/src/bin/pngthermal/linux-32
--------------------------------------------------------------------------------
/src/bin/pngthermal/linux-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alrra/dotfiles/HEAD/src/bin/pngthermal/linux-64
--------------------------------------------------------------------------------
/src/shell/bash_logout:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Clear console on exit.
4 |
5 | [ "$SHLVL" == 1 ] \
6 | && clear &> /dev/null
7 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/close_system_preferences_panes.applescript:
--------------------------------------------------------------------------------
1 | #!/usr/bin/osascript
2 |
3 | tell application "System Preferences" to quit
4 |
--------------------------------------------------------------------------------
/src/shell/ubuntu/bash_autocompletion:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
4 | . /etc/bash_completion
5 | fi
6 |
--------------------------------------------------------------------------------
/src/git/gitattributes:
--------------------------------------------------------------------------------
1 | # Automatically normalize line endings for all text-based files.
2 | # https://git-scm.com/docs/gitattributes#_end_of_line_conversion
3 | #
4 | # * text=auto
5 |
--------------------------------------------------------------------------------
/src/shell/bash_init:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Load OS specific configs.
6 |
7 | . "$OS/bash_init"
8 |
--------------------------------------------------------------------------------
/src/shell/bash_autocompletion:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Load OS specific configs.
6 |
7 | . "$OS/bash_autocompletion"
8 |
--------------------------------------------------------------------------------
/src/os/installs/macos/vim.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "./utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | brew_install "Vim" "vim"
9 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/vim.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "./utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | install_package "Vim" "vim-gtk3"
9 |
--------------------------------------------------------------------------------
/src/os/preferences/ubuntu/main.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")"
4 |
5 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 |
7 | ./privacy.sh
8 | ./terminal.sh
9 | ./ui_and_ux.sh
10 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/cleanup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "./utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Cleanup\n\n"
9 | autoremove
10 |
--------------------------------------------------------------------------------
/src/os/installs/main.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n • Installs\n\n"
9 |
10 | "./$(get_os)/main.sh"
11 |
--------------------------------------------------------------------------------
/.markdownlint.json:
--------------------------------------------------------------------------------
1 | {
2 | "header-style": {
3 | "style": "setext_with_atx"
4 | },
5 | "line-length": {
6 | "code_blocks": false,
7 | "tables": false
8 | },
9 | "strong-style": {
10 | "style": "underscore"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/os/preferences/main.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n • Preferences\n"
9 |
10 | "./$(get_os)/main.sh"
11 |
--------------------------------------------------------------------------------
/src/os/installs/macos/git.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Git\n\n"
10 |
11 | brew_install "Git" "git"
12 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/git.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Git\n\n"
10 |
11 | install_package "Git" "git"
12 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/tmux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n tmux\n\n"
10 |
11 | install_package "tmux" "tmux"
12 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/misc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Miscellaneous\n\n"
10 |
11 | install_package "VLC" "vlc"
12 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/image_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Image Tools\n\n"
10 |
11 | install_package "ImageMagick" "imagemagick"
12 |
--------------------------------------------------------------------------------
/src/os/installs/macos/gpg.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n GPG\n\n"
10 |
11 | brew_install "GPG" "gpg"
12 | brew_install "Pinentry" "pinentry-mac"
13 |
--------------------------------------------------------------------------------
/src/os/installs/macos/tmux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n tmux\n\n"
10 |
11 | brew_install "tmux" "tmux"
12 | brew_install "Pasteboard" "reattach-to-user-namespace"
13 |
--------------------------------------------------------------------------------
/src/os/installs/macos/compression_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Compression Tools\n\n"
10 |
11 | brew_install "Brotli" "brotli"
12 | brew_install "Zopfli" "zopfli"
13 |
--------------------------------------------------------------------------------
/src/os/installs/macos/video_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Video Tools\n\n"
10 |
11 | brew_install "AtomicParsley" "atomicparsley"
12 | brew_install "FFmpeg" "ffmpeg"
13 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/compression_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Compression Tools\n\n"
10 |
11 | install_package "Brotli" "brotli"
12 | install_package "Zopfli" "zopfli"
13 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/security_and_privacy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Security & Privacy\n\n"
9 |
10 | execute "defaults write com.apple.AdLib allowApplePersonalizedAdvertising -int 0" \
11 | "Disable personalized ads"
12 |
--------------------------------------------------------------------------------
/src/vim/vim/snippets/emmet.json:
--------------------------------------------------------------------------------
1 | {
2 | "html": {
3 | "snippets": {
4 | "html5": "\n\n
\n\t\n\t\n\t\n\n\n\n\t${child}\n\n"
5 | },
6 | "variables": {
7 | "lang": "en"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/os/installs/macos/image_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Image Tools\n\n"
10 |
11 | brew_install "ImageMagick" "imagemagick"
12 | brew_install "ImageOptim" "imageoptim" "--cask"
13 | brew_install "pngquant" "pngquant"
14 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/firefox.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Firefox\n\n"
9 |
10 | execute "defaults write org.mozilla.firefox AppleEnableSwipeNavigateWithScrolls -bool false" \
11 | "Disable backswipe"
12 |
13 | killall "firefox" &> /dev/null
14 |
--------------------------------------------------------------------------------
/src/os/installs/macos/misc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Miscellaneous\n\n"
10 |
11 | brew_install "Rectangle" "rectangle" "--cask"
12 | brew_install "Unarchiver" "the-unarchiver" "--cask"
13 | brew_install "VLC" "vlc" "--cask"
14 |
--------------------------------------------------------------------------------
/src/os/installs/macos/misc_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Miscellaneous Tools\n\n"
10 |
11 | brew_install "eyeD3" "eye-d3"
12 | brew_install "pdfcpu" "pdfcpu"
13 | brew_install "ShellCheck" "shellcheck"
14 | brew_install "Yarn" "yarn"
15 |
--------------------------------------------------------------------------------
/src/os/preferences/ubuntu/privacy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Privacy\n\n"
9 |
10 | execute "gsettings set com.canonical.Unity.Lenses remote-content-search 'none'" \
11 | "Turn off 'Remote Search' so that search terms in Dash do not get sent over the internet"
12 |
--------------------------------------------------------------------------------
/src/os/restart.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | main() {
9 |
10 | print_in_purple "\n • Restart\n\n"
11 |
12 | ask_for_confirmation "Do you want to restart?"
13 | printf "\n"
14 |
15 | if answer_is_yes; then
16 | sudo shutdown -r now &> /dev/null
17 | fi
18 |
19 | }
20 |
21 | main
22 |
--------------------------------------------------------------------------------
/src/os/preferences/ubuntu/terminal.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Terminal\n\n"
9 |
10 | execute "gsettings set org.gnome.desktop.interface monospace-font-name 'Monospace 12'" \
11 | "Change font size"
12 |
13 | execute "./set_terminal_theme.sh" \
14 | "Set custom terminal theme"
15 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/photos.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Photos\n\n"
9 |
10 | execute "defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true" \
11 | "Prevent Photos from opening automatically when devices are plugged in"
12 |
13 | killall "Photos" &> /dev/null
14 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/language_and_region.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Language & Region\n\n"
9 |
10 | execute "defaults write -g AppleLanguages -array 'en'" \
11 | "Set language"
12 |
13 | execute "defaults write -g AppleMeasurementUnits -string 'Centimeters'" \
14 | "Set measurement units"
15 |
--------------------------------------------------------------------------------
/src/os/installs/macos/browsers.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Browsers\n"
10 |
11 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12 |
13 | printf "\n"
14 |
15 | brew_install "Chrome" "google-chrome" "--cask"
16 | brew_install "Firefox" "firefox" "--cask"
17 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/main.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | update
10 | upgrade
11 |
12 | ./build-essentials.sh
13 |
14 | ./git.sh
15 | ./compression_tools.sh
16 | ./image_tools.sh
17 | ./misc.sh
18 | ./misc_tools.sh
19 | ./../volta.sh
20 | ./../npm.sh
21 | ./tmux.sh
22 | ./../vim.sh
23 |
24 | ./cleanup.sh
25 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/main.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")"
4 |
5 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 |
7 | ./init.sh
8 |
9 | ./app_store.sh
10 | ./chrome.sh
11 | ./dock.sh
12 | ./finder.sh
13 | ./firefox.sh
14 | ./keyboard.sh
15 | ./language_and_region.sh
16 | ./maps.sh
17 | ./photos.sh
18 | ./safari.sh
19 | ./security_and_privacy.sh
20 | ./terminal.sh
21 | ./textedit.sh
22 | ./trackpad.sh
23 | ./ui_and_ux.sh
24 |
--------------------------------------------------------------------------------
/src/os/installs/macos/web_font_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Web Font Tools\n\n"
10 |
11 | brew_install "TTF/OTF → WOFF (Zopfli)" "sfnt2woff-zopfli" "" "bramstein/webfonttools"
12 | brew_install "TTF/OTF → WOFF" "sfnt2woff" "" "bramstein/webfonttools"
13 | brew_install "WOFF2" "woff2" "" "bramstein/webfonttools"
14 |
--------------------------------------------------------------------------------
/src/os/preferences/ubuntu/ui_and_ux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n UI & UX\n\n"
9 |
10 | execute "gsettings set org.gnome.desktop.background picture-options 'stretched'" \
11 | "Set desktop background image options"
12 |
13 | execute "gsettings set org.gnome.libgnomekbd.keyboard layouts \"[ 'us', 'ro' ]\"" \
14 | "Set keyboard languages"
15 |
--------------------------------------------------------------------------------
/src/os/installs/macos/main.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | ./xcode.sh
10 | ./homebrew.sh
11 |
12 | reload_local_shell_configs
13 | ./bash.sh
14 |
15 | ./git.sh
16 | ./../volta.sh
17 | ./browsers.sh
18 | ./compression_tools.sh
19 | ./gpg.sh
20 | ./image_tools.sh
21 | ./misc.sh
22 | ./misc_tools.sh
23 | ./../npm.sh
24 | ./tmux.sh
25 | ./video_tools.sh
26 | ./../vim.sh
27 | ./vscode.sh
28 | ./web_font_tools.sh
29 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/maps.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Maps\n\n"
9 |
10 | execute "defaults write com.apple.Maps LastClosedWindowViewOptions '{
11 | localizeLabels = 1; // show labels in English
12 | mapType = 11; // show hybrid map
13 | trafficEnabled = 0; // do not show traffic
14 | }'" \
15 | "Set view options"
16 |
17 | killall "Maps" &> /dev/null
18 |
--------------------------------------------------------------------------------
/src/os/installs/npm.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | install_npm_package() {
9 |
10 | execute \
11 | ". $HOME/.bash.local \
12 | && npm install --global --silent $2" \
13 | "$1"
14 |
15 | }
16 |
17 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18 |
19 | main() {
20 |
21 | print_in_purple "\n npm\n\n"
22 |
23 | install_npm_package "Update npm" "npm"
24 |
25 | }
26 |
27 | main
28 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/textedit.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n TextEdit\n\n"
9 |
10 | execute "defaults write com.apple.TextEdit PlainTextEncoding -int 4 && \
11 | defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4" \
12 | "Open and save files as UTF-8 encoded"
13 |
14 | execute "defaults write com.apple.TextEdit RichText 0" \
15 | "Use plain text mode for new documents"
16 |
17 | killall "TextEdit" &> /dev/null
18 |
--------------------------------------------------------------------------------
/src/os/preferences/ubuntu/set_terminal_theme.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 |
7 | declare tmpDir="$(mktemp --directory)"
8 |
9 | # Use external script to set the Solarized color set.
10 | git clone https://github.com/aruhier/gnome-terminal-colors-solarized.git "$tmpDir"
11 | cd "$tmpDir"
12 |
13 | # Ensured the right (reviewed) script is executed.
14 | git checkout -b main 9651c41df0f89e87feee0c798779abba0f9395e0
15 |
16 | # Run script and automatically respond to all prompts
17 | printf "1\nYES\n" | ./set_dark.sh
18 |
19 | # Clean up.
20 | rm -rf "$tmpDir"
21 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/chrome.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Chrome\n\n"
9 |
10 | execute "defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false" \
11 | "Disable backswipe"
12 |
13 | execute "defaults write com.google.Chrome PMPrintingExpandedStateForPrint2 -bool true" \
14 | "Expand print dialog by default"
15 |
16 | execute "defaults write com.google.Chrome DisablePrintPreview -bool true" \
17 | "Use system-native print preview dialog"
18 |
19 | killall "Google Chrome" &> /dev/null
20 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/build-essentials.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Build Essentials\n\n"
10 |
11 | # Install tools for compiling/building software from source.
12 | install_package "Build Essential" "build-essential"
13 |
14 | # GnuPG archive keys of the Debian archive.
15 | install_package "GnuPG archive keys" "debian-archive-keyring"
16 |
17 | # Software which is not included by default
18 | # in Ubuntu due to legal or copyright reasons.
19 | #install_package "Ubuntu Restricted Extras" "ubuntu-restricted-extras"
20 |
--------------------------------------------------------------------------------
/src/shell/macos/bash_init:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Set up Homebrew.
6 |
7 | set_homebrew() {
8 | HARDWARE="$(uname -m)"
9 | prefix=""
10 |
11 | if [ "$HARDWARE" == "arm64" ]; then
12 | prefix="/opt/homebrew"
13 | elif [ "$HARDWARE" == "x86_64" ]; then
14 | prefix="/usr/local"
15 | fi
16 |
17 | eval "$($prefix/bin/brew shellenv)"
18 | }
19 |
20 | set_homebrew
21 | unset -f set_homebrew
22 |
23 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24 |
25 | # Configure Homebrew to not auto-update before running commands
26 | # such as: `brew install`, `brew upgrade`, and `brew tap`.
27 | #
28 | # https://docs.brew.sh/Manpage#environment
29 |
30 | export HOMEBREW_NO_AUTO_UPDATE=1
31 |
--------------------------------------------------------------------------------
/src/shell/curlrc:
--------------------------------------------------------------------------------
1 | # cURL configuration options.
2 | # https://curl.haxx.se/docs/manpage.html
3 |
4 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5 |
6 | # Limit the time (in seconds) the connection is allowed to take.
7 |
8 | connect-timeout = 60
9 |
10 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11 |
12 | # Follow HTTP redirects.
13 |
14 | location
15 |
16 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17 |
18 | # Display progress as a simple progress bar.
19 |
20 | progress-bar
21 |
22 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 |
24 | # Show error messages.
25 |
26 | show-error
27 |
28 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 |
30 | # Send a fake UA string for the HTTP servers that sniff it.
31 |
32 | user-agent = "Mozilla/5.0 Gecko"
33 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/misc_tools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | print_in_purple "\n Miscellaneous Tools\n\n"
10 |
11 | install_package "cURL" "curl"
12 | install_package "ShellCheck" "shellcheck"
13 | install_package "xclip" "xclip"
14 |
15 | if ! package_is_installed "yarn"; then
16 |
17 | add_key "https://dl.yarnpkg.com/debian/pubkey.gpg" \
18 | || print_error "Yarn (add key)"
19 |
20 | add_to_source_list "https://dl.yarnpkg.com/debian/ stable main" "yarn.list" \
21 | || print_error "Yarn (add to package resource list)"
22 |
23 | update &> /dev/null \
24 | || print_error "Yarn (resync package index files)"
25 |
26 | fi
27 |
28 | install_package "Yarn" "yarn" "--no-install-recommends"
29 |
--------------------------------------------------------------------------------
/src/os/installs/macos/vscode.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | install_plugin() {
10 | execute "code --install-extension $2" "$1 plugin"
11 | }
12 |
13 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 |
15 | print_in_purple "\n Visual Studio Code\n\n"
16 |
17 | # Install VSCode
18 | brew_install "Visual Studio Code" "visual-studio-code" "--cask"
19 |
20 | printf "\n"
21 |
22 | # Install the VSCode plugins
23 | install_plugin "EditorConfig" "EditorConfig.EditorConfig"
24 | install_plugin "File Icons" "vscode-icons-team.vscode-icons"
25 | install_plugin "MarkdownLint" "DavidAnson.vscode-markdownlint"
26 | install_plugin "Vim" "vscodevim.vim"
27 |
28 | # Close VSCode
29 | osascript -e 'quit app "Visual Studio Code"'
30 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/app_store.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n App Store\n\n"
9 |
10 | execute "defaults write com.apple.appstore ShowDebugMenu -bool true" \
11 | "Enable debug menu"
12 |
13 | execute "defaults write com.apple.commerce AutoUpdate -bool true" \
14 | "Turn on auto-update"
15 |
16 | execute "defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true" \
17 | "Enable automatic update check"
18 |
19 | execute "defaults write com.apple.SoftwareUpdate AutomaticDownload -int 1" \
20 | "Download newly available updates in background"
21 |
22 | execute "defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 1" \
23 | "Install System data files and security updates"
24 |
25 | killall "App Store" &> /dev/null
26 |
--------------------------------------------------------------------------------
/src/os/update_content.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | main() {
9 |
10 | ssh -T git@github.com &> /dev/null
11 |
12 | if [ $? -ne 1 ]; then
13 | ./set_github_ssh_key.sh \
14 | || return 1
15 | fi
16 |
17 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18 |
19 | print_in_purple "\n • Update content\n\n"
20 |
21 | ask_for_confirmation "Do you want to update the content from the 'dotfiles' directory?"
22 |
23 | if answer_is_yes; then
24 |
25 | git fetch --all 1> /dev/null \
26 | && git reset --hard origin/main 1> /dev/null \
27 | && git checkout main &> /dev/null \
28 | && git clean -fd 1> /dev/null
29 |
30 | print_result $? "Update content"
31 |
32 | fi
33 |
34 | }
35 |
36 | main
37 |
--------------------------------------------------------------------------------
/src/shell/macos/bash_autocompletion:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if command -v brew &> /dev/null; then
4 |
5 | declare BASH_COMPLETION_PATH="$(brew --prefix 2> /dev/null)/etc/profile.d/bash_completion.sh"
6 |
7 | if [ -r "$BASH_COMPLETION_PATH" ]; then
8 |
9 | # Ensure existing `bash-completion@1` continues to work.
10 | # https://github.com/Homebrew/homebrew-core/pull/36254
11 |
12 | export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d"
13 |
14 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 |
16 | # Use the latest `bash-completion`.
17 |
18 | . "$BASH_COMPLETION_PATH"
19 |
20 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21 |
22 | # Make Bash complete the `g` alias just like it does `git`.
23 |
24 | __git_complete g git
25 |
26 | fi
27 |
28 | elif [ -f /etc/bash_completion ]; then
29 | . /etc/bash_completion;
30 | fi
31 |
--------------------------------------------------------------------------------
/src/os/installs/vim.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | install_plugins() {
9 |
10 | declare -r VIM_PACK_DIR="$HOME/.vim/pack"
11 | declare -r MINPAC_DIR="$VIM_PACK_DIR/minpac/opt/minpac"
12 | declare -r MINPAC_GIT_REPO_URL="https://github.com/k-takata/minpac.git"
13 |
14 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 |
16 | # Install plugins.
17 |
18 | execute \
19 | "rm -rf $VIM_PACK_DIR \
20 | && git clone --quiet $MINPAC_GIT_REPO_URL $MINPAC_DIR" \
21 | "Install plugins" \
22 | || return 1
23 |
24 | vim +PluginsSetup
25 |
26 | }
27 |
28 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 |
30 | main() {
31 |
32 | print_in_purple "\n Vim\n\n"
33 |
34 | "./$(get_os)/vim.sh"
35 | install_plugins
36 |
37 | }
38 |
39 | main
40 |
--------------------------------------------------------------------------------
/src/os/installs/volta.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | add_configs() {
9 | # Check if the configs need to be added.
10 | if command -v volta &> /dev/null; then
11 | return
12 | fi
13 |
14 | update_local_shell_configs "export PATH=\"\$HOME/.volta/bin:\$PATH\" # Volta"
15 | }
16 |
17 | install() {
18 | execute \
19 | "curl https://get.volta.sh | bash -s -- --skip-setup" \
20 | "Install"
21 | }
22 |
23 | install_node() {
24 |
25 | # Install Node.js LTS.
26 | # Note: This will also set it as the default.
27 |
28 | execute "volta install node" \
29 | "Install Node.js LTS"
30 |
31 | }
32 |
33 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34 |
35 | main() {
36 |
37 | print_in_purple "\n Volta\n\n"
38 |
39 | install
40 | add_configs
41 | install_node
42 |
43 | }
44 |
45 | main
46 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/terminal.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Terminal\n\n"
9 |
10 | execute "defaults write com.apple.terminal FocusFollowsMouse -string true" \
11 | "Make the focus automatically follow the mouse"
12 |
13 | execute "defaults write com.apple.terminal SecureKeyboardEntry -bool true" \
14 | "Enable 'Secure Keyboard Entry'"
15 |
16 | execute "defaults write com.apple.Terminal ShowLineMarks -int 0" \
17 | "Hide line marks"
18 |
19 | execute "defaults write com.apple.terminal StringEncodings -array 4" \
20 | "Only use UTF-8"
21 |
22 | execute "./set_terminal_theme.applescript" \
23 | "Set custom terminal theme"
24 |
25 | # Ensure the Touch ID is used when `sudo` is required.
26 |
27 | if ! grep -q "pam_tid.so" "/etc/pam.d/sudo"; then
28 | execute "sudo sh -c 'echo \"auth sufficient pam_tid.so\" >> /etc/pam.d/sudo'" \
29 | "Use Touch ID to authenticate sudo"
30 | fi
31 |
--------------------------------------------------------------------------------
/src/shell/macos/bash_colors:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Set LSCOLORS (FreeBSD / macOS).
6 | #
7 | # * `ls` displays colors if the `-G` option is passed or if
8 | # the `CLICOLOR` environment variable is set.
9 | #
10 | # * The actual colors are configured through the `LSCOLORS`
11 | # environment variable (built-in defaults are used if this
12 | # variable is not set).
13 |
14 | LSCOLORS=""
15 |
16 | LSCOLORS+="gx" # Directory
17 | LSCOLORS+="fx" # Symbolic link
18 | LSCOLORS+="cx" # Socket
19 | LSCOLORS+="dx" # Pipe
20 | LSCOLORS+="cx" # Executable
21 | LSCOLORS+="eg" # Block special
22 | LSCOLORS+="ed" # Character special
23 | LSCOLORS+="ab" # Executable with setuid bit set
24 | LSCOLORS+="ag" # Executable with setgid bit set
25 | LSCOLORS+="cc" # Directory writable to others, with sticky bit
26 | LSCOLORS+="bd" # Directory writable to others, without sticky bit
27 |
28 | export LSCOLORS
29 |
30 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 |
32 | # Enable color support.
33 |
34 | alias ls="ls -G"
35 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) Cătălin Mariș
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 | of the Software, and to permit persons to whom the Software is furnished to do
8 | so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/init.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | # Check if the terminal has "Full Disk Access", and if it does
9 | # not, ask the user to grant it.
10 | #
11 | # This is required in order to be able to set some preferences.
12 | # See also: https://lapcatsoftware.com/articles/containers.html.
13 |
14 | if ! ls "$HOME/Library/Containers/com.apple.Safari/Data" &> /dev/null; then
15 | printf "\n"
16 |
17 | # Open the "Full Disk Access" system preferences.
18 | open "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"
19 |
20 | # Ask the user to grant "Full Disk Access".
21 | ask "Please grant the terminal \"Full Disk Access\" and then press any key to continue. "
22 | fi
23 |
24 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25 |
26 | # Close any open "System Preferences" panes in order to
27 | # avoid overriding the preferences that are being changed.
28 |
29 | ./close_system_preferences_panes.applescript
30 |
--------------------------------------------------------------------------------
/src/os/initialize_git_repository.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | initialize_git_repository() {
9 |
10 | declare -r GIT_ORIGIN="$1"
11 |
12 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13 |
14 | if [ -z "$GIT_ORIGIN" ]; then
15 | print_error "Please provide a URL for the Git origin"
16 | exit 1
17 | fi
18 |
19 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 |
21 | if ! is_git_repository; then
22 |
23 | # Run the following Git commands in the root of
24 | # the dotfiles directory, not in the `os/` directory.
25 |
26 | cd ../../ \
27 | || print_error "Failed to 'cd ../../'"
28 |
29 | execute \
30 | "git init && git remote add origin $GIT_ORIGIN" \
31 | "Initialize the Git repository"
32 |
33 | fi
34 |
35 | }
36 |
37 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38 |
39 | main() {
40 | print_in_purple "\n • Initialize Git repository\n\n"
41 | initialize_git_repository "$1"
42 | }
43 |
44 | main "$1"
45 |
--------------------------------------------------------------------------------
/src/shell/bash_aliases:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | alias ..="cd .."
4 | alias ...="cd ../.."
5 | alias ....="cd ../../.."
6 | alias cd..="cd .."
7 |
8 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 |
10 | alias cp="cp -iv"
11 | # │└─ list copied files
12 | # └─ prompt before overwriting an existing file
13 |
14 | alias mkdir="mkdir -pv"
15 | # │└─ list created directories
16 | # └─ create intermediate directories
17 |
18 | alias mv="mv -iv"
19 | # │└─ list moved files
20 | # └─ prompt before overwriting an existing file
21 |
22 | alias rm="rm -rf --"
23 |
24 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25 |
26 | alias :q="exit"
27 | alias c="clear"
28 | alias ch="history -c && > ~/.bash_history"
29 | alias d="cd ~/Desktop"
30 | alias e="vim --"
31 | alias g="git"
32 | alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
33 | alias ll="ls -lA"
34 | alias n="npm"
35 | alias p="cd ~/projects"
36 | alias path='printf "%b\n" "${PATH//:/\\n}"'
37 | alias q="exit"
38 | alias t="tmux"
39 | alias y="yarn"
40 |
41 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 |
43 | # Load OS specific configs.
44 |
45 | . "$OS/bash_aliases"
46 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/trackpad.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Trackpad\n\n"
9 |
10 | execute "defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true && \
11 | defaults write com.apple.AppleMultitouchTrackpad Clicking -int 1 && \
12 | defaults write -g com.apple.mouse.tapBehavior -int 1 && \
13 | defaults -currentHost write -g com.apple.mouse.tapBehavior -int 1" \
14 | "Enable 'Tap to click'"
15 |
16 | execute "defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true && \
17 | defaults write com.apple.AppleMultitouchTrackpad TrackpadRightClick -int 1 && \
18 | defaults -currentHost write -g com.apple.trackpad.enableSecondaryClick -bool true && \
19 | defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 0 && \
20 | defaults write com.apple.AppleMultitouchTrackpad TrackpadCornerSecondaryClick -int 0 && \
21 | defaults -currentHost write -g com.apple.trackpad.trackpadCornerClickBehavior -int 0" \
22 | "Map 'click or tap with two fingers' to the secondary click"
23 |
--------------------------------------------------------------------------------
/src/shell/ubuntu/bash_colors:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Set LS_COLORS (GNU).
6 | #
7 | # - `ls` displays colors if the `--color` option is passed.
8 | #
9 | # - The actual colors are configured through the `LS_COLORS`
10 | # environment variable (built-in defaults are used if this
11 | # variable is not set).
12 |
13 | LS_COLORS=""
14 |
15 | LS_COLORS+="no=0;39:" # Global default
16 | LS_COLORS+="di=0;36:" # Directory
17 | LS_COLORS+="ex=0;32:" # Executable file
18 | LS_COLORS+="fi=0;39:" # File
19 | LS_COLORS+="ec=:" # Non-filename text
20 | LS_COLORS+="mi=1;31:" # Non-existent file pointed to by a symlink
21 | LS_COLORS+="ln=target:" # Symbolic link
22 | LS_COLORS+="or=31;01" # Symbolic link pointing to a non-existent file
23 |
24 | export LS_COLORS
25 |
26 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27 |
28 | # Enable color support.
29 |
30 | if [ -x /usr/bin/dircolors ]; then
31 |
32 | if test -r ~/.dircolors; then
33 | eval "$(dircolors -b ~/.dircolors)"
34 | fi
35 |
36 | alias dir="dir --color=auto"
37 | alias egrep="egrep --color=auto"
38 | alias fgrep="fgrep --color=auto"
39 | alias grep="grep --color=auto"
40 | alias ls="ls --color=auto"
41 | alias vdir="vdir --color=auto"
42 |
43 | fi
44 |
--------------------------------------------------------------------------------
/src/shell/ubuntu/bash_aliases:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Lock screen.
6 |
7 | alias afk="gnome-screensaver-command --lock"
8 |
9 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 |
11 | # Shorter commands for the `Advanced Packaging Tool`
12 |
13 | alias apti="sudo apt-get install"
14 | alias aptr="sudo apt-get remove"
15 | alias apts="sudo apt-cache search"
16 | alias aptu="sudo apt-get update \
17 | && sudo apt-get upgrade"
18 |
19 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 |
21 | # Empty trash.
22 |
23 | alias empty-trash="rm -rf ~/.local/share/Trash/files/*"
24 |
25 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 |
27 | # Hide/Show desktop icons.
28 |
29 | alias hide-desktop-icons="gsettings set org.gnome.desktop.background show-desktop-icons false"
30 | alias show-desktop-icons="gsettings set org.gnome.desktop.background show-desktop-icons true"
31 |
32 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 |
34 | # Open from the terminal.
35 |
36 | alias o="xdg-open"
37 |
38 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 |
40 | # Update applications and CLTs.
41 |
42 | alias u="sudo apt-get update \
43 | && sudo apt-get upgrade"
44 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/keyboard.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Keyboard\n\n"
9 |
10 | execute "defaults write -g AppleKeyboardUIMode -int 3" \
11 | "Enable full keyboard access for all controls"
12 |
13 | execute "defaults write -g ApplePressAndHoldEnabled -bool false" \
14 | "Disable press-and-hold in favor of key repeat"
15 |
16 | execute "defaults write -g 'InitialKeyRepeat_Level_Saved' -int 10" \
17 | "Set delay until repeat"
18 |
19 | execute "defaults write -g KeyRepeat -int 1" \
20 | "Set the key repeat rate to fast"
21 |
22 | execute "defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false" \
23 | "Disable automatic capitalization"
24 |
25 | execute "defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false" \
26 | "Disable automatic correction"
27 |
28 | execute "defaults write -g NSAutomaticPeriodSubstitutionEnabled -bool false" \
29 | "Disable automatic period substitution"
30 |
31 | execute "defaults write -g NSAutomaticDashSubstitutionEnabled -bool false" \
32 | "Disable smart dashes"
33 |
34 | execute "defaults write -g NSAutomaticQuoteSubstitutionEnabled -bool false" \
35 | "Disable smart quotes"
36 |
37 | execute "defaults write com.apple.HIToolbox AppleFnUsageType -int 2" \
38 | "Remap the emoji picker to the Fn key"
39 |
--------------------------------------------------------------------------------
/src/shell/inputrc:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Readline library configuration options.
4 | # http://ss64.com/bash/syntax-inputrc.html
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | # If there are multiple matches for completion,
9 | # make TAB cycle through them.
10 |
11 | TAB: menu-complete
12 |
13 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 |
15 | # Searching files via partial match.
16 |
17 | # ↑
18 | "\e[A":history-search-backward
19 | # ↓
20 | "\e[B":history-search-forward
21 |
22 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 |
24 | # Disable beeping and window flashing.
25 |
26 | set bell-style none
27 |
28 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 |
30 | # Use the `vi` set of key bindings (default is `emacs`).
31 |
32 | set editing-mode vi
33 |
34 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
35 |
36 | # Use case-insensitive TAB autocompletion.
37 |
38 | set completion-ignore-case on
39 |
40 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 |
42 | # Perform partial completion on the first Tab press, and
43 | # only start cycling full results on the second Tab press.
44 |
45 | set menu-complete-display-prefix on
46 |
47 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 |
49 | # Display a list of the matching files
50 |
51 | set show-all-if-ambiguous on
52 |
--------------------------------------------------------------------------------
/src/shell/bash_profile:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | source_bash_files() {
6 | declare -r CURRENT_DIRECTORY="$(pwd)"
7 |
8 | declare -r -a FILES_TO_SOURCE=(
9 | "bash_init"
10 |
11 | "bash_aliases"
12 | "bash_autocompletion"
13 | "bash_exports"
14 | "bash_functions"
15 | "bash_options"
16 | "bash_prompt"
17 |
18 | "bash.local" # For local settings that should
19 | # not be under version control.
20 | )
21 |
22 | local file=""
23 | local i=""
24 |
25 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 |
27 | cd "$(dirname "$(readlink "${BASH_SOURCE[0]}")")" \
28 | && . "../os/utils.sh"
29 |
30 | # shellcheck disable=SC2034
31 | declare -r OS="$(get_os)"
32 |
33 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34 |
35 | for i in ${!FILES_TO_SOURCE[*]}; do
36 |
37 | file="$HOME/.${FILES_TO_SOURCE[$i]}"
38 |
39 | [ -r "$file" ] \
40 | && . "$file"
41 |
42 | done
43 |
44 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 |
46 | cd "$CURRENT_DIRECTORY"
47 |
48 | }
49 |
50 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 |
52 | source_bash_files
53 | unset -f source_bash_files
54 |
55 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56 |
57 | # Clear system messages (system copyright notice, the date
58 | # and time of the last login, the message of the day, etc.).
59 |
60 | clear
61 |
--------------------------------------------------------------------------------
/src/git/gitignore:
--------------------------------------------------------------------------------
1 | # Useful `.gitignore` templates:
2 | # https://github.com/github/gitignore
3 |
4 | # ----------------------------------------------------------------------
5 | # | Linux |
6 | # ----------------------------------------------------------------------
7 |
8 | *~
9 |
10 |
11 | # ----------------------------------------------------------------------
12 | # | Miscellaneous |
13 | # ----------------------------------------------------------------------
14 |
15 | # Node.js, npm, and yarn.
16 |
17 | node_modules
18 | npm-debug.log*
19 | yarn-debug.log*
20 | yarn-error.log*
21 |
22 |
23 | # ----------------------------------------------------------------------
24 | # | macOS |
25 | # ----------------------------------------------------------------------
26 |
27 | ._*
28 | .AppleDouble
29 | .DS_Store
30 | .localized
31 | .LSOverride
32 | .Spotlight-V100
33 | .Trashes
34 |
35 |
36 | # ----------------------------------------------------------------------
37 | # | Vim |
38 | # ----------------------------------------------------------------------
39 |
40 | %*
41 | *.sw[a-z]
42 | *.un~
43 | .netrwhist
44 | Session.vim
45 |
46 |
47 | # ----------------------------------------------------------------------
48 | # | Windows |
49 | # ----------------------------------------------------------------------
50 |
51 | Desktop.ini
52 | ehthumbs.db
53 | Thumbs.db
54 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/set_terminal_theme.applescript:
--------------------------------------------------------------------------------
1 | #!/usr/bin/osascript
2 |
3 | tell application "Terminal"
4 |
5 | local allOpenedWindows
6 | local initialOpenedWindows
7 | local windowID
8 |
9 | set themeName to "Solarized Dark"
10 |
11 | (* Store the IDs of all the open terminal windows. *)
12 | set initialOpenedWindows to id of every window
13 |
14 | (* Open the custom theme so that it gets added to the list
15 | of available terminal themes (note: this will open two
16 | additional terminal windows). *)
17 | do shell script "open '" & themeName & ".terminal'"
18 |
19 | (* Wait a little bit to ensure that the custom theme is added. *)
20 | delay 1
21 |
22 | (* Set the custom theme as the default terminal theme. *)
23 | set default settings to settings set themeName
24 |
25 | (* Get the IDs of all the currently opened terminal windows. *)
26 | set allOpenedWindows to id of every window
27 |
28 | repeat with windowID in allOpenedWindows
29 |
30 | (* Close the additional windows that were opened in order
31 | to add the custom theme to the list of terminal themes. *)
32 | if initialOpenedWindows does not contain windowID then
33 | close (every window whose id is windowID)
34 |
35 | (* Change the theme for the initial opened terminal windows
36 | to remove the need to close them in order for the custom
37 | theme to be applied. *)
38 | else
39 | set current settings of tabs of (every window whose id is windowID) to settings set themeName
40 | end if
41 |
42 | end repeat
43 |
44 | end tell
45 |
--------------------------------------------------------------------------------
/src/os/installs/ubuntu/utils.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | add_key() {
9 |
10 | wget -qO - "$1" | sudo apt-key add - &> /dev/null
11 | # │└─ write output to file
12 | # └─ don't show output
13 |
14 | }
15 |
16 | add_ppa() {
17 | sudo add-apt-repository -y ppa:"$1" &> /dev/null
18 | }
19 |
20 | add_to_source_list() {
21 | sudo sh -c "printf 'deb $1' >> '/etc/apt/sources.list.d/$2'"
22 | }
23 |
24 | autoremove() {
25 |
26 | # Remove packages that were automatically installed to satisfy
27 | # dependencies for other packages and are no longer needed.
28 |
29 | execute \
30 | "sudo apt-get autoremove -qqy" \
31 | "APT (autoremove)"
32 |
33 | }
34 |
35 | install_package() {
36 |
37 | declare -r EXTRA_ARGUMENTS="$3"
38 | declare -r PACKAGE="$2"
39 | declare -r PACKAGE_READABLE_NAME="$1"
40 |
41 | if ! package_is_installed "$PACKAGE"; then
42 | execute "sudo apt-get install --allow-unauthenticated -qqy $EXTRA_ARGUMENTS $PACKAGE" "$PACKAGE_READABLE_NAME"
43 | # suppress output ─┘│
44 | # assume "yes" as the answer to all prompts ──┘
45 | else
46 | print_success "$PACKAGE_READABLE_NAME"
47 | fi
48 |
49 | }
50 |
51 | package_is_installed() {
52 | dpkg -s "$1" &> /dev/null
53 | }
54 |
55 | update() {
56 |
57 | # Resynchronize the package index files from their sources.
58 |
59 | execute \
60 | "sudo apt-get update -qqy" \
61 | "APT (update)"
62 |
63 | }
64 |
65 | upgrade() {
66 |
67 | # Install the newest versions of all packages installed.
68 |
69 | execute \
70 | "export DEBIAN_FRONTEND=\"noninteractive\" \
71 | && sudo apt-get -o Dpkg::Options::=\"--force-confnew\" upgrade -qqy" \
72 | "APT (upgrade)"
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/os/installs/macos/bash.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | change_default_bash() {
10 | local newShellPath=""
11 | local brewPrefix=""
12 |
13 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 |
15 | brewPrefix="$(brew_prefix)" \
16 | || return 1
17 |
18 | newShellPath="$brewPrefix/bin/bash" \
19 |
20 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21 |
22 | # Add the path of the `Bash` version installed through `Homebrew`
23 | # to the list of login shells from the `/etc/shells` file.
24 | #
25 | # This needs to be done because applications use this file to
26 | # determine whether a shell is valid (e.g.: `chsh` consults the
27 | # `/etc/shells` to determine whether an unprivileged user may
28 | # change the login shell for her own account).
29 | #
30 | # http://www.linuxfromscratch.org/blfs/view/7.4/postlfs/etcshells.html
31 |
32 | if ! grep "$newShellPath" < /etc/shells &> /dev/null; then
33 | execute \
34 | "printf '%s\n' '$newShellPath' | sudo tee -a /etc/shells" \
35 | "Add '$newShellPath' in '/etc/shells'" \
36 | || return 1
37 | fi
38 |
39 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 |
41 | # Set latest version of `Bash` as the default
42 | # (macOS uses by default an older version of `Bash`).
43 |
44 | chsh -s "$newShellPath" &> /dev/null
45 | print_result $? "Make OS use the latest version of Bash"
46 |
47 | }
48 |
49 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 |
51 | main() {
52 |
53 | print_in_purple "\n Bash\n\n"
54 |
55 | brew_install "Bash" "bash" \
56 | && change_default_bash
57 |
58 | brew_install "Bash Completion 2" "bash-completion@2"
59 |
60 | }
61 |
62 | main
63 |
--------------------------------------------------------------------------------
/src/os/create_local_config_files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | create_bash_local() {
9 |
10 | declare -r FILE_PATH="$HOME/.bash.local"
11 |
12 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13 |
14 | if [ ! -e "$FILE_PATH" ] || [ -z "$FILE_PATH" ]; then
15 |
16 | DOTFILES_BIN_DIR="$(dirname "$(pwd)")/bin/"
17 |
18 | printf "%s\n" \
19 | "#!/bin/bash
20 |
21 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22 |
23 | # Set PATH additions.
24 |
25 | PATH=\"$DOTFILES_BIN_DIR:\$PATH\"
26 |
27 | export PATH" \
28 | >> "$FILE_PATH"
29 | fi
30 |
31 | print_result $? "$FILE_PATH"
32 |
33 | }
34 |
35 | create_gitconfig_local() {
36 |
37 | declare -r FILE_PATH="$HOME/.gitconfig.local"
38 |
39 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 |
41 | if [ ! -e "$FILE_PATH" ] || [ -z "$FILE_PATH" ]; then
42 |
43 | printf "%s\n" \
44 | "[commit]
45 |
46 | # Sign commits using GPG.
47 | # https://help.github.com/articles/signing-commits-using-gpg/
48 |
49 | # gpgsign = true
50 |
51 |
52 | [user]
53 |
54 | name =
55 | email =
56 | # signingkey =" \
57 | >> "$FILE_PATH"
58 | fi
59 |
60 | print_result $? "$FILE_PATH"
61 |
62 | }
63 |
64 | create_vimrc_local() {
65 |
66 | declare -r FILE_PATH="$HOME/.vimrc.local"
67 |
68 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69 |
70 | if [ ! -e "$FILE_PATH" ]; then
71 | printf "" >> "$FILE_PATH"
72 | fi
73 |
74 | print_result $? "$FILE_PATH"
75 |
76 | }
77 |
78 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79 |
80 | main() {
81 |
82 | print_in_purple "\n • Create local config files\n\n"
83 |
84 | create_bash_local
85 | create_gitconfig_local
86 | create_vimrc_local
87 |
88 | }
89 |
90 | main
91 |
--------------------------------------------------------------------------------
/src/shell/bash_options:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Bash options.
4 | # https://www.gnu.org/software/bash/manual/bashref.html#The-Shopt-Builtin
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | # Enable `vi` editing mode.
9 | # https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Readline-vi-Mode
10 |
11 | set -o vi
12 |
13 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 |
15 | # Automatically prepend `cd` to directory names.
16 |
17 | shopt -s autocd
18 |
19 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 |
21 | # Autocorrect typos in path names when using the `cd` command.
22 |
23 | shopt -s cdspell
24 |
25 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 |
27 | # Check the window size after each command and, if necessary, update
28 | # the values of `LINES` and `COLUMNS`.
29 |
30 | shopt -s checkwinsize
31 |
32 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 |
34 | # Save all lines of a multiple-line command in the same history entry.
35 |
36 | shopt -s cmdhist
37 |
38 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 |
40 | # Include filenames beginning with a "." in the filename expansion.
41 |
42 | shopt -s dotglob
43 |
44 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 |
46 | # Use extended pattern matching features.
47 |
48 | shopt -s extglob
49 |
50 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 |
52 | # Append to the history file rather then overwriting it.
53 |
54 | shopt -s histappend
55 |
56 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 |
58 | # Do not attempt to search the PATH for possible completions when
59 | # completion is attempted on an empty line.
60 |
61 | shopt -s no_empty_cmd_completion
62 |
63 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64 |
65 | # Match filenames in a case-insensitive fashion when performing
66 | # filename expansion.
67 |
68 | shopt -s nocaseglob
69 |
--------------------------------------------------------------------------------
/src/os/installs/macos/utils.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | brew_install() {
9 |
10 | declare -r ARGUMENTS="$3"
11 | declare -r FORMULA="$2"
12 | declare -r FORMULA_READABLE_NAME="$1"
13 | declare -r TAP_VALUE="$4"
14 |
15 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16 |
17 | # Check if `Homebrew` is installed.
18 |
19 | if ! cmd_exists "brew"; then
20 | print_error "$FORMULA_READABLE_NAME ('Homebrew' is not installed)"
21 | return 1
22 | fi
23 |
24 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25 |
26 | # If `brew tap` needs to be executed,
27 | # check if it executed correctly.
28 |
29 | if [ -n "$TAP_VALUE" ]; then
30 | if ! brew_tap "$TAP_VALUE"; then
31 | print_error "$FORMULA_READABLE_NAME ('brew tap $TAP_VALUE' failed)"
32 | return 1
33 | fi
34 | fi
35 |
36 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 |
38 | # Install the specified formula.
39 |
40 | # shellcheck disable=SC2086
41 | if brew list "$FORMULA" &> /dev/null; then
42 | print_success "$FORMULA_READABLE_NAME"
43 | else
44 | execute \
45 | "brew install $FORMULA $ARGUMENTS" \
46 | "$FORMULA_READABLE_NAME"
47 | fi
48 |
49 | }
50 |
51 | brew_prefix() {
52 |
53 | local path=""
54 |
55 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56 |
57 | if path="$(brew --prefix 2> /dev/null)"; then
58 | printf "%s" "$path"
59 | return 0
60 | else
61 | print_error "Homebrew (get prefix)"
62 | return 1
63 | fi
64 |
65 | }
66 |
67 | brew_tap() {
68 | brew tap "$1" &> /dev/null
69 | }
70 |
71 | brew_update() {
72 |
73 | execute \
74 | "brew update" \
75 | "Homebrew (update)"
76 |
77 | }
78 |
79 | brew_upgrade() {
80 |
81 | execute \
82 | "brew upgrade" \
83 | "Homebrew (upgrade)"
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/shell/macos/bash_aliases:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Lock screen.
6 |
7 | alias afk="osascript -e 'tell application \"System Events\" to sleep'"
8 |
9 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 |
11 | # Shorter commands for `Homebrew`.
12 |
13 | alias brewd="brew doctor"
14 | alias brewi="brew install"
15 | alias brewr="brew uninstall"
16 | alias brews="brew search"
17 | alias brewu="brew update --quiet \
18 | && brew upgrade \
19 | && brew cleanup"
20 |
21 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22 |
23 | # Clear DNS cache.
24 |
25 | alias clear-dns-cache="sudo dscacheutil -flushcache; \
26 | sudo killall -HUP mDNSResponder"
27 |
28 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 |
30 | # Empty the trash, the main HDD and on all mounted volumes,
31 | # and clear Apple’s system logs to improve shell startup speed.
32 |
33 | alias empty-trash="sudo rm -frv /Volumes/*/.Trashes; \
34 | sudo rm -frv ~/.Trash; \
35 | sudo rm -frv /private/var/log/asl/*.asl; \
36 | sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'"
37 |
38 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 |
40 | # Hide/Show desktop icons.
41 |
42 | alias hide-desktop-icons="defaults write com.apple.finder CreateDesktop -bool false \
43 | && killall Finder"
44 |
45 | alias show-desktop-icons="defaults write com.apple.finder CreateDesktop -bool true \
46 | && killall Finder"
47 |
48 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49 |
50 | # Open from the terminal.
51 |
52 | alias o="open"
53 |
54 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 |
56 | # Update applications and CLTs.
57 |
58 | alias u="sudo softwareupdate --install --all \
59 | && brew update \
60 | && brew upgrade \
61 | && brew cleanup"
62 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/safari.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Safari\n\n"
9 |
10 | execute "defaults write com.apple.Safari AutoOpenSafeDownloads -bool false" \
11 | "Disable opening 'safe' files automatically"
12 |
13 | execute "defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool true" \
14 | "Set backspace key to go to the previous page in history"
15 |
16 | execute "defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true && \
17 | defaults write com.apple.Safari IncludeDevelopMenu -bool true && \
18 | defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true" \
19 | "Enable the 'Develop' menu and the 'Web Inspector'"
20 |
21 | execute "defaults write com.apple.Safari EnableEnhancedPrivacyInPrivateBrowsing -bool true &&
22 | defaults write com.apple.Safari EnableEnhancedPrivacyInRegularBrowsing -bool true " \
23 | "Use advanced tracking and fingerprinting protection in all browsing."
24 |
25 | execute "defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false" \
26 | "Set search type to 'Contains' instead of 'Starts With'"
27 |
28 | execute "defaults write com.apple.Safari HomePage -string 'about:blank'" \
29 | "Set home page to 'about:blank'"
30 |
31 | execute "defaults write com.apple.Safari IncludeInternalDebugMenu -bool true" \
32 | "Enable 'Debug' menu"
33 |
34 | execute "defaults write com.apple.Safari ShowFavoritesBar -bool false" \
35 | "Hide bookmarks bar by default"
36 |
37 | execute "defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true" \
38 | "Show the full URL in the address bar"
39 |
40 | execute "defaults write com.apple.Safari SuppressSearchSuggestions -bool true && \
41 | defaults write com.apple.Safari UniversalSearchEnabled -bool false" \
42 | "Don’t send search queries to Apple"
43 |
44 | execute "defaults write -g WebKitDeveloperExtras -bool true" \
45 | "Add a context menu item for showing the 'Web Inspector' in web views"
46 |
47 | execute "defaults write com.apple.Safari WebKitInitialTimedLayoutDelay 0.25" \
48 | "Disable the standard delay in rendering a web page."
49 |
50 | killall "Safari" &> /dev/null
51 |
--------------------------------------------------------------------------------
/src/os/installs/macos/xcode.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | agree_with_xcode_licence() {
9 |
10 | # Automatically agree to the terms of the `Xcode` license.
11 | # https://github.com/alrra/dotfiles/issues/10
12 |
13 | sudo xcodebuild -license accept &> /dev/null
14 | print_result $? "Agree to the terms of the Xcode licence"
15 |
16 | }
17 |
18 | are_xcode_command_line_tools_installed() {
19 | xcode-select --print-path &> /dev/null
20 | }
21 |
22 | install_xcode() {
23 |
24 | # If necessary, prompt user to install `Xcode`.
25 |
26 | if ! is_xcode_installed; then
27 | open "macappstores://itunes.apple.com/en/app/xcode/id497799835"
28 | fi
29 |
30 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 |
32 | # Wait until `Xcode` is installed.
33 |
34 | execute \
35 | "until is_xcode_installed; do \
36 | sleep 5; \
37 | done" \
38 | "Install Xcode.app"
39 |
40 | }
41 |
42 | install_xcode_command_line_tools() {
43 |
44 | # If necessary, prompt user to install
45 | # the `Xcode Command Line Tools`.
46 |
47 | xcode-select --install &> /dev/null
48 |
49 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 |
51 | # Wait until the `Xcode Command Line Tools` are installed.
52 |
53 | execute \
54 | "until are_xcode_command_line_tools_installed; do \
55 | sleep 5; \
56 | done" \
57 | "Install Xcode Command Line Tools"
58 |
59 | }
60 |
61 | is_xcode_installed() {
62 | [ -d "/Applications/Xcode.app" ]
63 | }
64 |
65 | set_xcode_developer_directory() {
66 |
67 | # Point the `xcode-select` developer directory to
68 | # the appropriate directory from within `Xcode.app`.
69 | #
70 | # https://github.com/alrra/dotfiles/issues/13
71 |
72 | sudo xcode-select -switch "/Applications/Xcode.app/Contents/Developer" &> /dev/null
73 | print_result $? "Make 'xcode-select' developer directory point to the appropriate directory from within Xcode.app"
74 |
75 | }
76 |
77 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78 |
79 | main() {
80 |
81 | print_in_purple " Xcode\n\n"
82 |
83 | install_xcode_command_line_tools
84 | install_xcode
85 | set_xcode_developer_directory
86 | agree_with_xcode_licence
87 |
88 | }
89 |
90 | main
91 |
--------------------------------------------------------------------------------
/src/os/create_symbolic_links.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | create_symlinks() {
9 |
10 | declare -a FILES_TO_SYMLINK=(
11 |
12 | "shell/bash_aliases"
13 | "shell/bash_autocompletion"
14 | "shell/bash_exports"
15 | "shell/bash_functions"
16 | "shell/bash_init"
17 | "shell/bash_logout"
18 | "shell/bash_options"
19 | "shell/bash_profile"
20 | "shell/bash_prompt"
21 | "shell/bashrc"
22 | "shell/curlrc"
23 | "shell/inputrc"
24 |
25 | "git/gitattributes"
26 | "git/gitconfig"
27 | "git/gitignore"
28 |
29 | "tmux/tmux.conf"
30 |
31 | "vim/vim"
32 | "vim/vimrc"
33 |
34 | )
35 |
36 | local i=""
37 | local sourceFile=""
38 | local targetFile=""
39 | local skipQuestions=false
40 |
41 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 |
43 | skip_questions "$@" \
44 | && skipQuestions=true
45 |
46 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47 |
48 | for i in "${FILES_TO_SYMLINK[@]}"; do
49 |
50 | sourceFile="$(cd .. && pwd)/$i"
51 | targetFile="$HOME/.$(printf "%s" "$i" | sed "s/.*\/\(.*\)/\1/g")"
52 |
53 | if [ ! -e "$targetFile" ] || $skipQuestions; then
54 |
55 | execute \
56 | "ln -fs $sourceFile $targetFile" \
57 | "$targetFile → $sourceFile"
58 |
59 | elif [ "$(readlink "$targetFile")" == "$sourceFile" ]; then
60 | print_success "$targetFile → $sourceFile"
61 | else
62 |
63 | if ! $skipQuestions; then
64 |
65 | ask_for_confirmation "'$targetFile' already exists, do you want to overwrite it?"
66 | if answer_is_yes; then
67 |
68 | rm -rf "$targetFile"
69 |
70 | execute \
71 | "ln -fs $sourceFile $targetFile" \
72 | "$targetFile → $sourceFile"
73 |
74 | else
75 | print_error "$targetFile → $sourceFile"
76 | fi
77 |
78 | fi
79 |
80 | fi
81 |
82 | done
83 |
84 | }
85 |
86 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 |
88 | main() {
89 | print_in_purple "\n • Create symbolic links\n\n"
90 | create_symlinks "$@"
91 | }
92 |
93 | main "$@"
94 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/dock.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Dock\n\n"
9 |
10 | execute "defaults write com.apple.dock autohide -bool true" \
11 | "Automatically hide/show the Dock"
12 |
13 | execute "defaults write com.apple.dock autohide-delay -float 0" \
14 | "Disable the hide Dock delay"
15 |
16 | execute "defaults write com.apple.dock enable-spring-load-actions-on-all-items -bool true" \
17 | "Enable spring loading for all Dock items"
18 |
19 | execute "defaults write com.apple.dock expose-animation-duration -float 0.1" \
20 | "Make all Mission Control related animations faster."
21 |
22 | execute "defaults write com.apple.dock expose-group-by-app -bool false" \
23 | "Do not group windows by application in Mission Control"
24 |
25 | execute "defaults write com.apple.dock launchanim -bool false" \
26 | "Disable the opening of an application from the Dock animations."
27 |
28 | execute "defaults write com.apple.dock mineffect -string 'scale'" \
29 | "Change minimize/maximize window effect"
30 |
31 | execute "defaults write com.apple.dock minimize-to-application -bool true" \
32 | "Reduce clutter by minimizing windows into their application icons"
33 |
34 | execute "defaults write com.apple.dock mru-spaces -bool false" \
35 | "Do not automatically rearrange spaces based on most recent use"
36 |
37 | execute "defaults write com.apple.dock persistent-apps -array && \
38 | defaults write com.apple.dock persistent-others -array " \
39 | "Wipe all app icons"
40 |
41 | execute "defaults write com.apple.dock show-process-indicators -bool true" \
42 | "Show indicator lights for open applications"
43 |
44 | execute "defaults write com.apple.dock show-recents -bool false" \
45 | "Do not show recent applications in Dock"
46 |
47 | execute "defaults write com.apple.dock showhidden -bool true" \
48 | "Make icons of hidden applications translucent"
49 |
50 | execute "defaults write com.apple.dock tilesize -int 60" \
51 | "Set icon size"
52 |
53 | execute "defaults write com.apple.dock wvous-tr-corner -int 0" \
54 | "Disable top right hot corner"
55 |
56 | execute "defaults write com.apple.dock wvous-tl-corner -int 0" \
57 | "Disable top left hot corner"
58 |
59 | execute "defaults write com.apple.dock wvous-bl-corner -int 0" \
60 | "Disable bottom left hot corner"
61 |
62 | execute "defaults write com.apple.dock wvous-br-corner -int 0" \
63 | "Disable bottom right hot corner"
64 |
65 | killall "Dock" &> /dev/null
66 |
--------------------------------------------------------------------------------
/src/os/installs/macos/homebrew.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh" \
5 | && . "./utils.sh"
6 |
7 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 |
9 | add_to_path() {
10 |
11 | # Check if `brew` is available.
12 |
13 | if command -v brew &> /dev/null; then
14 | return
15 | fi
16 |
17 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18 |
19 | # If not, add it to the PATH.
20 |
21 | HARDWARE="$(uname -m)"
22 | brewPrefix=""
23 |
24 | if [ "$HARDWARE" == "arm64" ]; then
25 | brewPrefix="/opt/homebrew"
26 | elif [ "$HARDWARE" == "x86_64" ]; then
27 | brewPrefix="/usr/local"
28 | else
29 | print_error "Homebrew is only supported on Intel and ARM processors!"
30 | fi
31 |
32 | update_local_shell_configs "export PATH=\"$brewPrefix/bin:\$PATH\" # Homebrew"
33 | }
34 |
35 | get_git_config_file_path() {
36 |
37 | local path=""
38 |
39 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 |
41 | if path="$(brew --repository 2> /dev/null)/.git/config"; then
42 | printf "%s" "$path"
43 | return 0
44 | else
45 | print_error "Get config file path"
46 | return 1
47 | fi
48 |
49 | }
50 |
51 | install() {
52 |
53 | if ! cmd_exists "brew"; then
54 | ask_for_sudo
55 | printf "\n" | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" &> /dev/null
56 | # └─ simulate the ENTER keypress
57 | fi
58 |
59 | print_result $? "Install"
60 |
61 | }
62 |
63 | opt_out_of_analytics() {
64 |
65 | local path=""
66 |
67 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 |
69 | # Try to get the path of the `Homebrew` git config file.
70 |
71 | path="$(get_git_config_file_path)" \
72 | || return 1
73 |
74 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75 |
76 | # Opt-out of Homebrew's analytics.
77 | # https://github.com/Homebrew/brew/blob/0c95c60511cc4d85d28f66b58d51d85f8186d941/share/doc/homebrew/Analytics.md#opting-out
78 |
79 | if [ "$(git config --file="$path" --get homebrew.analyticsdisabled)" != "true" ]; then
80 | git config --file="$path" --replace-all homebrew.analyticsdisabled true &> /dev/null
81 | print_result $? "Opt-out of analytics"
82 | fi
83 |
84 | }
85 |
86 | update() {
87 | execute \
88 | "brew update" \
89 | "Update"
90 | }
91 |
92 | upgrade() {
93 | execute \
94 | "brew upgrade" \
95 | "Upgrade"
96 | }
97 |
98 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99 |
100 | main() {
101 |
102 | print_in_purple "\n Homebrew\n\n"
103 |
104 | install
105 | add_to_path
106 | opt_out_of_analytics
107 |
108 | update
109 | upgrade
110 | }
111 |
112 | main
113 |
--------------------------------------------------------------------------------
/src/os/set_github_ssh_key.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | add_ssh_configs() {
9 |
10 | printf "%s\n" \
11 | "Host github.com" \
12 | " IdentityFile $1" \
13 | " LogLevel ERROR" >> ~/.ssh/config
14 |
15 | print_result $? "Add SSH configs"
16 |
17 | }
18 |
19 | copy_public_ssh_key_to_clipboard () {
20 |
21 | if cmd_exists "pbcopy"; then
22 |
23 | pbcopy < "$1"
24 | print_result $? "Copy public SSH key to clipboard"
25 |
26 | elif cmd_exists "xclip"; then
27 |
28 | xclip -selection clip < "$1"
29 | print_result $? "Copy public SSH key to clipboard"
30 |
31 | else
32 | print_warning "Please copy the public SSH key ($1) to clipboard"
33 | fi
34 |
35 | }
36 |
37 | generate_ssh_keys() {
38 |
39 | ask "Please provide an email address: " && printf "\n"
40 | ssh-keygen -t rsa -b 4096 -C "$(get_answer)" -f "$1"
41 |
42 | print_result $? "Generate SSH keys"
43 |
44 | }
45 |
46 | open_github_ssh_page() {
47 |
48 | declare -r GITHUB_SSH_URL="https://github.com/settings/ssh"
49 |
50 | # The order of the following checks matters
51 | # as on Ubuntu there is also a utility called `open`.
52 |
53 | if cmd_exists "xdg-open"; then
54 | xdg-open "$GITHUB_SSH_URL"
55 | elif cmd_exists "open"; then
56 | open "$GITHUB_SSH_URL"
57 | else
58 | print_warning "Please add the public SSH key to GitHub ($GITHUB_SSH_URL)"
59 | fi
60 |
61 | }
62 |
63 | set_github_ssh_key() {
64 |
65 | local sshKeyFileName="$HOME/.ssh/github"
66 |
67 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 |
69 | # If there is already a file with that
70 | # name, generate another, unique, file name.
71 |
72 | if [ -f "$sshKeyFileName" ]; then
73 | sshKeyFileName="$(mktemp -u "$HOME/.ssh/github_XXXXX")"
74 | fi
75 |
76 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 |
78 | generate_ssh_keys "$sshKeyFileName"
79 | add_ssh_configs "$sshKeyFileName"
80 | copy_public_ssh_key_to_clipboard "${sshKeyFileName}.pub"
81 | open_github_ssh_page
82 | test_ssh_connection \
83 | && rm "${sshKeyFileName}.pub"
84 |
85 | }
86 |
87 | test_ssh_connection() {
88 |
89 | while true; do
90 |
91 | ssh -T git@github.com &> /dev/null
92 | [ $? -eq 1 ] && break
93 |
94 | sleep 5
95 |
96 | done
97 |
98 | }
99 |
100 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 |
102 | main() {
103 |
104 | print_in_purple "\n • Set up GitHub SSH keys\n\n"
105 |
106 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107 |
108 | if ! is_git_repository; then
109 | print_error "Not a Git repository"
110 | exit 1
111 | fi
112 |
113 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114 |
115 | ssh -T git@github.com &> /dev/null
116 |
117 | if [ $? -ne 1 ]; then
118 | set_github_ssh_key
119 | fi
120 |
121 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
122 |
123 | print_result $? "Set up GitHub SSH keys"
124 |
125 | }
126 |
127 | main
128 |
--------------------------------------------------------------------------------
/src/shell/bash_exports:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Bash Variables.
4 | # https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | # Stop the macOS Terminal from showing a warning
9 | # message when Zsh is not the default shell.
10 | #
11 | # https://support.apple.com/en-us/HT208050
12 |
13 | export BASH_SILENCE_DEPRECATION_WARNING=1
14 |
15 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16 |
17 | # Make `vim` the default editor.
18 |
19 | export EDITOR="vim"
20 |
21 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22 |
23 | # Ignore commands that start with spaces and duplicates.
24 |
25 | export HISTCONTROL=ignoreboth
26 |
27 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28 |
29 | # Increase the maximum number of lines of history
30 | # persisted in the history file (default value is 500).
31 |
32 | export HISTFILESIZE=10000
33 |
34 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
35 |
36 | # Don't add certain commands to the history file.
37 |
38 | export HISTIGNORE="&:[bf]g:c:clear:history:exit:q:pwd:* --help"
39 |
40 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 |
42 | # Increase the maximum number of commands recorded
43 | # in the command history (default value is 500).
44 |
45 | export HISTSIZE=10000
46 |
47 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 |
49 | # Prefer US English and use UTF-8 encoding.
50 |
51 | export LANG="en_US"
52 | export LC_ALL="en_US.UTF-8"
53 |
54 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 |
56 | # Use custom `less` colors for `man` pages.
57 |
58 | export LESS_TERMCAP_md="$(tput bold 2> /dev/null; tput setaf 2 2> /dev/null)"
59 | export LESS_TERMCAP_me="$(tput sgr0 2> /dev/null)"
60 |
61 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62 |
63 | # Don't clear the screen after quitting a `man` page.
64 |
65 | export MANPAGER="less -X"
66 |
67 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 |
69 | # Enable the module compile cache for the Node.js instance.
70 | #
71 | # https://nodejs.org/api/cli.html#node_compile_cachedir
72 | # https://nodejs.org/en/blog/release/v22.1.0#module-implement-node_compile_cache-for-automatic-on-disk-code-caching
73 |
74 | export NODE_COMPILE_CACHE="$HOME/.cache/node_compile_cache"
75 |
76 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 |
78 | # Increase the maximum number of lines of history persisted
79 | # in the `Node` REPL history file (default value is 1000).
80 | #
81 | # https://github.com/nodejs/node/blob/c948877688ff2b6a37f2c88724b656aae495c7b2/doc/api/repl.md#persistent-history
82 |
83 | export NODE_REPL_HISTORY_SIZE=10000
84 |
85 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86 |
87 | # If not set, make new shells get the history lines from all previous
88 | # shells instead of the default "last window closed" history.
89 |
90 | if ! printf "%s" "$PROMPT_COMMAND" | grep "history -a" &> /dev/null; then
91 | export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
92 | fi
93 |
94 | # Remove `update_terminal_cwd` from the `PROMPT_COMMAND`
95 | # environment variable if it doesn't exist in the current shell.
96 | #
97 | # On macOS `update_terminal_cwd` is added to the `PROMPT_COMMAND`
98 | # environment variable however, `/etc/bashrc_Apple_Terminal`
99 | # that contains the shell function definition is only executed
100 | # for `Terminal.app`. Other terminals (e.g.: VS Code's terminal)
101 | # will not have the shell function, hence, they will show the
102 | #
103 | # bash: update_terminal_cwd: command not found
104 | #
105 | # error everytime the prompt is displayed.
106 |
107 | if printf "%s" "$PROMPT_COMMAND" | grep "update_terminal_cwd" &> /dev/null &&
108 | ! command -v update_terminal_cwd &> /dev/null; then
109 | export PROMPT_COMMAND="$(printf "%s" "$PROMPT_COMMAND" | sed 's/\(.*\)update_terminal_cwd;*\(.*\)/\1\2/g')"
110 | fi
111 |
112 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113 |
114 | # Make Python use UTF-8 encoding for output to stdin/stdout/stderr.
115 |
116 | export PYTHONIOENCODING="UTF-8"
117 |
--------------------------------------------------------------------------------
/src/tmux/tmux.conf:
--------------------------------------------------------------------------------
1 | # tmux settings
2 | # http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1#x4f5054494f4e53
3 |
4 |
5 | # ----------------------------------------------------------------------
6 | # | General Settings |
7 | # ----------------------------------------------------------------------
8 |
9 | # Make window index start at 1
10 | set -g base-index 1
11 |
12 | # Make pane index start at 1
13 | setw -g pane-base-index 1
14 |
15 | # Remove delay when sending commands
16 | # (default is 500 milliseconds)
17 | set -sg escape-time 1
18 |
19 |
20 | # ----------------------------------------------------------------------
21 | # | Key Mappings |
22 | # ----------------------------------------------------------------------
23 |
24 | # Change the key combination for the PREFIX key to `ctrl-a`
25 | set -g prefix C-a
26 | unbind-key C-b
27 |
28 | # Make tmux send the PREFIX to an application running
29 | # within tmux simply by pressing PREFIX key twice
30 | bind C-a send-prefix
31 |
32 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 |
34 | # Use vim keybindings in copy mode
35 | setw -g mode-keys vi
36 |
37 | # Workaround for accessing macOS' pasteboard
38 | # https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
39 |
40 | if-shell \
41 | 'test "$(uname -s)" = Darwin' \
42 | 'set-option -g default-command "exec reattach-to-user-namespace -l $SHELL"'
43 |
44 | # Remap the copy & paste keys to work as in vim
45 | unbind [
46 | bind Escape copy-mode
47 | unbind p
48 | bind p paste-buffer
49 | bind-key -T copy-mode-vi "v" send-keys -X begin-selection
50 | bind-key -T copy-mode-vi "y" send-keys -X copy-selection
51 |
52 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 |
54 | # [ PREFIX + - ] Split window horizontally
55 | bind - split-window -v
56 |
57 | # [ PREFIX + | ] Split window vertically
58 | bind | split-window -h
59 |
60 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61 |
62 | # [ PREFIX + h/j/k/l ] Move from pane to pane
63 | bind h select-pane -L
64 | bind j select-pane -D
65 | bind k select-pane -U
66 | bind l select-pane -R
67 |
68 | # [ PREFIX + H/J/K/L ] Resize pane
69 | bind -r H resize-pane -L 5
70 | bind -r J resize-pane -D 5
71 | bind -r K resize-pane -U 5
72 | bind -r L resize-pane -R 5
73 |
74 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75 |
76 | # [ PREFIX + r ] Reload tmux config
77 | bind r source-file ~/.tmux.conf \; display "tmux configs reloaded"
78 |
79 |
80 | # ----------------------------------------------------------------------
81 | # | Status bar |
82 | # ----------------------------------------------------------------------
83 |
84 | # Notified when something happens in one of the other windows
85 | setw -g monitor-activity on
86 | set -g visual-activity on
87 |
88 | # Periodically refresh the status bar
89 | set -g status-interval 60
90 |
91 | # Customize what is displayed
92 | set -g status-justify left
93 | set -g status-left-length 50
94 | set -g status-left " #S / "
95 | # └─ current session name
96 | set -g status-right " %R "
97 | # └─ current time
98 |
99 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 |
101 | # Default colors
102 | set -g status-bg green
103 | set -g status-fg black
104 |
105 | # Colors for window list
106 | setw -g window-status-style fg=black,bg=green,dim
107 |
108 | # Colors for active window
109 | setw -g window-status-current-style fg=black,bg=yellow,dim
110 |
111 |
112 | # ----------------------------------------------------------------------
113 | # | Visual Styling |
114 | # ----------------------------------------------------------------------
115 |
116 | # Display things in 256 colors
117 | set -g default-terminal "screen-256color"
118 |
119 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120 |
121 | # Command Line
122 | set -g message-style fg=black,bg=green,dim
123 |
124 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125 |
126 | # Pane divider
127 | set -g pane-active-border-style bg=default,fg=green
128 | set -g pane-border-style bg=default,fg=colour244
129 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/finder.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n Finder\n\n"
9 |
10 | execute "defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true && \
11 | defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true && \
12 | defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true" \
13 | "Automatically open a new Finder window when a volume is mounted"
14 |
15 | execute "defaults write com.apple.finder _FXShowPosixPathInTitle -bool true" \
16 | "Use full POSIX path as window title"
17 |
18 | execute "defaults write com.apple.finder DisableAllAnimations -bool true" \
19 | "Disable all animations"
20 |
21 | execute "defaults write com.apple.finder WarnOnEmptyTrash -bool false" \
22 | "Disable the warning before emptying the Trash"
23 |
24 | execute "defaults write com.apple.finder FXDefaultSearchScope -string 'SCcf'" \
25 | "Search the current directory by default"
26 |
27 | execute "defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false" \
28 | "Disable warning when changing a file extension"
29 |
30 | execute "defaults write com.apple.finder FXPreferredViewStyle -string 'Nlsv'" \
31 | "Use list view in all Finder windows by default"
32 |
33 | execute "defaults write com.apple.finder NewWindowTarget -string 'PfDe' && \
34 | defaults write com.apple.finder NewWindowTargetPath -string 'file://$HOME/Desktop/'" \
35 | "Set 'Desktop' as the default location for new Finder windows"
36 |
37 | execute "defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true && \
38 | defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true && \
39 | defaults write com.apple.finder ShowMountedServersOnDesktop -bool true && \
40 | defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true" \
41 | "Show icons for hard drives, servers, and removable media on the desktop"
42 |
43 | execute "defaults write com.apple.finder ShowRecentTags -bool false" \
44 | "Do not show recent tags"
45 |
46 | execute "defaults write -g AppleShowAllExtensions -bool true" \
47 | "Show all filename extensions"
48 |
49 | execute "/usr/libexec/PlistBuddy -c 'Set :DesktopViewSettings:IconViewSettings:iconSize 72' ~/Library/Preferences/com.apple.finder.plist && \
50 | /usr/libexec/PlistBuddy -c 'Set :StandardViewSettings:IconViewSettings:iconSize 72' ~/Library/Preferences/com.apple.finder.plist" \
51 | "Set icon size"
52 |
53 | execute "/usr/libexec/PlistBuddy -c 'Set :DesktopViewSettings:IconViewSettings:gridSpacing 1' ~/Library/Preferences/com.apple.finder.plist && \
54 | /usr/libexec/PlistBuddy -c 'Set :StandardViewSettings:IconViewSettings:gridSpacing 1' ~/Library/Preferences/com.apple.finder.plist" \
55 | "Set icon grid spacing size"
56 |
57 | execute "/usr/libexec/PlistBuddy -c 'Set :DesktopViewSettings:IconViewSettings:textSize 13' ~/Library/Preferences/com.apple.finder.plist && \
58 | /usr/libexec/PlistBuddy -c 'Set :StandardViewSettings:IconViewSettings:textSize 13' ~/Library/Preferences/com.apple.finder.plist" \
59 | "Set icon label text size"
60 |
61 | execute "/usr/libexec/PlistBuddy -c 'Set :DesktopViewSettings:IconViewSettings:labelOnBottom true' ~/Library/Preferences/com.apple.finder.plist && \
62 | /usr/libexec/PlistBuddy -c 'Set :StandardViewSettings:IconViewSettings:labelOnBottom true' ~/Library/Preferences/com.apple.finder.plist" \
63 | "Set icon label position"
64 |
65 | execute "/usr/libexec/PlistBuddy -c 'Set :DesktopViewSettings:IconViewSettings:showItemInfo true' ~/Library/Preferences/com.apple.finder.plist && \
66 | /usr/libexec/PlistBuddy -c 'Set :StandardViewSettings:IconViewSettings:showItemInfo true' ~/Library/Preferences/com.apple.finder.plist" \
67 | "Show item info"
68 |
69 | execute "/usr/libexec/PlistBuddy -c 'Set :DesktopViewSettings:IconViewSettings:arrangeBy none' ~/Library/Preferences/com.apple.finder.plist && \
70 | /usr/libexec/PlistBuddy -c 'Set :StandardViewSettings:IconViewSettings:arrangeBy none' ~/Library/Preferences/com.apple.finder.plist" \
71 | "Set sort method"
72 |
73 | killall "Finder" &> /dev/null
74 |
75 | # Starting with Mac OS X Mavericks preferences are cached,
76 | # so in order for things to get properly set using `PlistBuddy`,
77 | # the `cfprefsd` process also needs to be killed.
78 | #
79 | # https://github.com/alrra/dotfiles/commit/035dda057ddc6013ba21db3d2c30eeb51ba8f200
80 |
81 | killall "cfprefsd" &> /dev/null
82 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/ui_and_ux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$(dirname "${BASH_SOURCE[0]}")" \
4 | && . "../../utils.sh"
5 |
6 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 |
8 | print_in_purple "\n UI & UX\n\n"
9 |
10 | execute "defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true && \
11 | defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true" \
12 | "Avoid creating '.DS_Store' files on network or USB volumes"
13 |
14 | execute "defaults write com.apple.menuextra.battery ShowPercent -string 'NO'" \
15 | "Hide battery percentage from the menu bar"
16 |
17 | execute "sudo defaults write /Library/Preferences/com.apple.loginwindow showInputMenu -bool true" \
18 | "Show language menu in the top right corner of the boot screen"
19 |
20 | execute "defaults write com.apple.CrashReporter UseUNC 1" \
21 | "Make crash reports appear as notifications"
22 |
23 | execute "defaults write com.apple.LaunchServices LSQuarantine -bool false" \
24 | "Disable 'Are you sure you want to open this application?' dialog"
25 |
26 | execute "defaults write com.apple.print.PrintingPrefs 'Quit When Finished' -bool true" \
27 | "Automatically quit the printer app once the print jobs are completed"
28 |
29 | execute "defaults write com.apple.screencapture disable-shadow -bool true" \
30 | "Disable shadow in screenshots"
31 |
32 | execute "defaults write com.apple.screencapture location -string '$HOME/Desktop'" \
33 | "Save screenshots to the Desktop"
34 |
35 | execute "defaults write com.apple.screencapture show-thumbnail -bool false" \
36 | "Do not show thumbnail"
37 |
38 | execute "defaults write com.apple.screencapture type -string 'png'" \
39 | "Save screenshots as PNGs"
40 |
41 | execute "defaults write com.apple.screensaver askForPassword -int 1 && \
42 | defaults write com.apple.screensaver askForPasswordDelay -int 0"\
43 | "Require password immediately after into sleep or screen saver mode"
44 |
45 | execute "defaults write -g AppleFontSmoothing -int 2" \
46 | "Enable subpixel font rendering on non-Apple LCDs"
47 |
48 | execute "defaults write -g AppleShowScrollBars -string 'Always'" \
49 | "Always show scrollbars"
50 |
51 | execute "defaults write -g NSAutomaticWindowAnimationsEnabled -bool false" \
52 | "Disable window opening and closing animations."
53 |
54 | execute "defaults write -g NSDisableAutomaticTermination -bool true" \
55 | "Disable automatic termination of inactive apps"
56 |
57 | execute "defaults write -g NSNavPanelExpandedStateForSaveMode -bool true" \
58 | "Expand save panel by default"
59 |
60 | execute "defaults write -g NSTableViewDefaultSizeMode -int 2" \
61 | "Set sidebar icon size to medium"
62 |
63 | execute "defaults write -g NSUseAnimatedFocusRing -bool false" \
64 | "Disable the over-the-top focus ring animation"
65 |
66 | execute "defaults write -g NSWindowResizeTime -float 0.001" \
67 | "Accelerated playback when adjusting the window size."
68 |
69 | execute "defaults write -g PMPrintingExpandedStateForPrint -bool true" \
70 | "Expand print panel by default"
71 |
72 | execute "defaults write -g QLPanelAnimationDuration -float 0" \
73 | "Disable opening a Quick Look window animations."
74 |
75 | execute "defaults write com.apple.systempreferences NSQuitAlwaysKeepsWindows -bool false" \
76 | "Disable resume system-wide"
77 |
78 | execute "sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string 'Laptop' && \
79 | sudo scutil --set ComputerName 'laptop' && \
80 | sudo scutil --set HostName 'laptop' && \
81 | sudo scutil --set LocalHostName 'laptop'" \
82 | "Set computer name"
83 |
84 | execute "sudo systemsetup -setrestartfreeze on" \
85 | "Restart automatically if the computer freezes"
86 |
87 | execute "sudo defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState 0 && \
88 | sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist && \
89 | sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist" \
90 | "Turn Bluetooth off"
91 |
92 | execute "for domain in ~/Library/Preferences/ByHost/com.apple.systemuiserver.*; do
93 | sudo defaults write \"\${domain}\" dontAutoLoad -array \
94 | '/System/Library/CoreServices/Menu Extras/TimeMachine.menu' \
95 | '/System/Library/CoreServices/Menu Extras/Volume.menu'
96 | done \
97 | && sudo defaults write com.apple.systemuiserver menuExtras -array \
98 | '/System/Library/CoreServices/Menu Extras/Bluetooth.menu' \
99 | '/System/Library/CoreServices/Menu Extras/AirPort.menu' \
100 | '/System/Library/CoreServices/Menu Extras/Battery.menu' \
101 | '/System/Library/CoreServices/Menu Extras/Clock.menu'
102 | " \
103 | "Hide Time Machine and Volume icons from the menu bar"
104 |
105 | killall "SystemUIServer" &> /dev/null
106 |
--------------------------------------------------------------------------------
/src/bin/get-compression-heatmap:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # DESCRIPTION:
4 | #
5 | # Generate compression efficiency heatmap images for files / URLs.
6 | #
7 | # USAGE:
8 | #
9 | # get-compression-heatmap URL/FILE ...
10 | #
11 | # USEFUL LINKS:
12 | #
13 | # http://encode.ru/threads/1725-pngthermal-pseudo-thermal-view-of-create_heatmap_for_png-compression-efficiency
14 | # http://encode.ru/threads/1889-gzthermal-pseudo-thermal-view-of-Gzip-Deflate-compression-efficiency
15 |
16 | # ----------------------------------------------------------------------
17 |
18 | declare gzthermal=""
19 | declare pngthermal=""
20 |
21 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22 |
23 | cmd_exists() {
24 | command -v "$1" &> /dev/null
25 | }
26 |
27 | compress_file() {
28 | cat "$1" | tee >(gzip > "$2") &> /dev/null
29 | }
30 |
31 | create_heatmap_for_file() {
32 |
33 | local tmpFile="$1"
34 |
35 | if [ "$(get_file_mime_type "$1")" != "application/x-gzip" ]; then
36 | tmpFile="$(create_tmp_file)"
37 | compress_file "$1" "$tmpFile"
38 | fi \
39 | && "${gzthermal}" "$tmpFile" \
40 | && mv "gzthermal-result.png" "$2"
41 | # └─ this cannot be changed :(
42 |
43 | }
44 |
45 | create_heatmap_for_png() {
46 | "${pngthermal}" "$1" "$2"
47 | }
48 |
49 | create_heatmap_for_webpage() {
50 |
51 | declare -r -a CURL_DEFAULT_OPTIONS=(
52 | --connect-timeout 30
53 | --header "Accept-Encoding: gzip, deflate"
54 | --header "Cache-Control: no-cache" # Prevent intermediate
55 | # proxies from caching
56 | # the response.
57 |
58 | --location # If the page was moved
59 | # to a different location,
60 | # redo the request.
61 | --max-time 150
62 | --show-error
63 | --silent
64 | --user-agent "Mozilla/5.0 Gecko" # Send a fake UA string
65 | # for sites that sniff
66 | # it instead of using the
67 | # Accept-Encoding header.
68 | )
69 |
70 | local tmpFile="$(create_tmp_file)"
71 |
72 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73 |
74 | # Try to get the compressed version of the page, and if the
75 | # page isn't served compressed, `create_heatmap_for_file` will
76 | # take care of compressing it.
77 |
78 | curl "${CURL_DEFAULT_OPTIONS[@]}" "$1" &> /dev/null 1> "$tmpFile" \
79 | && create_heatmap_for_file "$tmpFile" "$2"
80 |
81 | }
82 |
83 | create_tmp_file() {
84 | printf "%s" "$(mktemp /tmp/XXXXX)"
85 | }
86 |
87 | get_file_mime_type() {
88 | printf "%s" "$(file "$1" --brief --mime-type)"
89 | }
90 |
91 | get_image_name() {
92 | printf "%s.png" "$(printf "%s" "$1" | sed 's/[^a-zA-Z0-9]/-/g')"
93 | }
94 |
95 | get_script_path() {
96 |
97 | declare -r os_name="$(uname -s)"
98 | local path="$1"
99 |
100 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 |
102 | if [ "$os_name" == "Darwin" ]; then
103 | path="$path/macos"
104 | elif [ "$os_name" == "Linux" ]; then
105 | path="$path/linux"
106 |
107 | if [ "$(uname -m)" == "x86_64" ]; then
108 | path="${path}-64"
109 | else
110 | path="${path}-31"
111 | fi
112 | fi
113 |
114 | printf "%s" "$(dirname "${BASH_SOURCE[0]}")/$path"
115 |
116 | }
117 |
118 | open_image() {
119 |
120 | # The order of the following checks matters as
121 | # on Ubuntu there is also a utility called `open`.
122 |
123 | if cmd_exists "xdg-open"; then
124 | xdg-open "$1"
125 | elif cmd_exists "open"; then
126 | open "$1"
127 | fi
128 |
129 | }
130 |
131 | print_error() {
132 | printf " [✖] %s\n" "$1"
133 | }
134 |
135 | print_result() {
136 |
137 | if [ "$1" -eq 0 ]; then
138 | print_success "$2"
139 | else
140 | print_error "$2"
141 | fi
142 |
143 | return "$1"
144 |
145 | }
146 |
147 | print_success() {
148 | printf " [✔] %s\n" "$1"
149 | }
150 |
151 | # ----------------------------------------------------------------------
152 |
153 | main() {
154 |
155 | # Check if `cURL` is installed
156 |
157 | if ! cmd_exists "curl"; then
158 | printf "cURL is required, please install it!\n"
159 | exit 1
160 | fi
161 |
162 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
163 |
164 | local imageFile=""
165 |
166 | gzthermal="$(get_script_path "gzthermal")"
167 | pngthermal="$(get_script_path "pngthermal")"
168 |
169 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170 |
171 | while [ $# -ne 0 ]; do
172 |
173 | imageFile="$(get_image_name "$1")"
174 |
175 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
176 |
177 | # Check if the current command
178 | # line argument is a local file.
179 |
180 | if [ -f "$1" ]; then
181 |
182 | if [ "$(get_file_mime_type "$1")" != "image/png" ]; then
183 | create_heatmap_for_file "$1" "$imageFile"
184 | else
185 | create_heatmap_for_png "$1" "$imageFile"
186 | fi
187 |
188 | # If it's not, assume it is a URL.
189 |
190 | else
191 | create_heatmap_for_webpage "$1" "$imageFile"
192 | fi
193 |
194 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
195 |
196 | print_result $? "$1" \
197 | && open_image "$imageFile"
198 |
199 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
200 |
201 | # Opening too many images really
202 | # quickly makes macOS' Preview crash.
203 |
204 | sleep 0.2
205 |
206 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207 |
208 | shift
209 |
210 | done
211 |
212 | }
213 |
214 | main "$@"
215 |
--------------------------------------------------------------------------------
/src/shell/bash_prompt:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | enable_color_support() {
6 |
7 | if [[ $COLORTERM == gnome-* && $TERM == xterm ]] \
8 | && infocmp gnome-256color &> /dev/null; then
9 | export TERM="gnome-256color"
10 | elif infocmp xterm-256color &> /dev/null; then
11 | export TERM="xterm-256color"
12 | fi
13 |
14 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 |
16 | # Load OS specific color support.
17 |
18 | . "$OS/bash_colors"
19 |
20 | }
21 |
22 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 |
24 | # [!] Don't break this function into smaller, more specialized ones
25 | # as you will only pollute the global space even more. This function
26 | # cannot be unset because it's called every time the prompt string
27 | # is shown.
28 |
29 | get_git_repository_details() {
30 |
31 | local branchName=""
32 | local tmp=""
33 |
34 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
35 |
36 | # Check if the current directory is in a Git repository.
37 |
38 | ! git rev-parse &>/dev/null \
39 | && return
40 |
41 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 |
43 | # Check if in `.git/` directory (some of the following
44 | # checks don't make sense/won't work in the `.git` directory).
45 |
46 | [ "$(git rev-parse --is-inside-git-dir)" == "true" ] \
47 | && return
48 |
49 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 |
51 | # Check for uncommitted changes in the index.
52 |
53 | if ! git diff --quiet --ignore-submodules --cached; then
54 | tmp="$tmp+";
55 | fi
56 |
57 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 |
59 | # Check for unstaged changes.
60 |
61 | if ! git diff-files --quiet --ignore-submodules --; then
62 | tmp="$tmp!";
63 | fi
64 |
65 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 |
67 | # Check for untracked files.
68 |
69 | if [ -n "$(git ls-files --others --exclude-standard)" ]; then
70 | tmp="$tmp?";
71 | fi
72 |
73 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74 |
75 | # Check for stashed files.
76 |
77 | if git rev-parse --verify refs/stash &>/dev/null; then
78 | tmp="$tmp$";
79 | fi
80 |
81 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82 |
83 | [ -n "$tmp" ] \
84 | && tmp=" [$tmp]"
85 |
86 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 |
88 | branchName="$( printf "%s" "$( git rev-parse --abbrev-ref HEAD 2> /dev/null \
89 | || git rev-parse --short HEAD 2> /dev/null \
90 | || printf " (unknown)" )" | \
91 | tr -d "\n" )"
92 |
93 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
94 |
95 | printf "%s" "$1$branchName$tmp"
96 |
97 | }
98 |
99 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 |
101 | set_prompts() {
102 |
103 | local bold=$(tput bold 2> /dev/null)
104 | local reset=$(tput sgr0 2> /dev/null)
105 |
106 | local cyan=""
107 | local green=""
108 | local orange=""
109 | local white=""
110 | local yellow=""
111 |
112 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113 |
114 | if [ "$(tput colors 2> /dev/null || printf "0")" -ge 256 ]; then
115 |
116 | # Solarized colors.
117 | # https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized#the-values
118 |
119 | cyan=$(tput setaf 37)
120 | green=$(tput setaf 64)
121 | orange=$(tput setaf 166)
122 | white=$(tput setaf 15)
123 | yellow=$(tput setaf 136)
124 |
125 | fi
126 |
127 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
128 |
129 | # Prompt Statement variables.
130 | # http://ss64.com/bash/syntax-prompt.html
131 |
132 | # ------------------------------------------------------------------
133 | # | PS1 - Default interactive prompt |
134 | # ------------------------------------------------------------------
135 |
136 | PS1="\[\033]0;\W\007\]" # Terminal title (set to the
137 | # current working directory)
138 |
139 | PS1+="$reset$bold"
140 | PS1+="$orange\u" # Username
141 | PS1+="$white@"
142 | PS1+="$yellow\h" # Host
143 | PS1+="$white: "
144 | PS1+="$green\w" # Working directory
145 | PS1+="\$(get_git_repository_details \"$white on $cyan\")"
146 | PS1+="\n"
147 | PS1+="\[$reset\]\[$white\]$ \[$reset\]"
148 |
149 | export PS1
150 |
151 | # ------------------------------------------------------------------
152 | # | PS2 - Continuation interactive prompt |
153 | # ------------------------------------------------------------------
154 |
155 | PS2="⚡ "
156 |
157 | export PS2
158 |
159 | # ------------------------------------------------------------------
160 | # | PS4 - Debug prompt |
161 | # ------------------------------------------------------------------
162 |
163 | # e.g:
164 | #
165 | # The GNU `date` command has the `%N` interpreted sequence while
166 | # other implementations don't (on macOS `gdate` can be used instead
167 | # of the native `date` if the `coreutils` package has been installed).
168 | #
169 | # local dateCmd=""
170 | #
171 | # if [ "$(date +%N)" != "N" ] || \
172 | # [ ! -x "$(command -v "gdate")" ]; then
173 | # dateCmd="date +%s.%N"
174 | # else
175 | # dateCmd="gdate +%s.%N"
176 | # fi
177 | #
178 | # PS4="+$( tput cr && tput cuf 6 &&
179 | # printf "$yellow %s $green%6s $reset" "$($dateCmd)" "[$LINENO]" )"
180 | #
181 | # PS4 output:
182 | #
183 | # ++ 1357074705.875970000 [123] '[' 1 == 0 ']'
184 | # └──┬─┘└────┬───┘ └───┬───┘ └──┬─┘ └──────┬─────┘
185 | # │ │ │ │ │
186 | # │ │ │ │ └─ command
187 | # │ │ │ └─ line number
188 | # │ │ └─ nanoseconds
189 | # │ └─ seconds since 1970-01-01 00:00:00 UTC
190 | # └─ depth-level of the subshell
191 |
192 | PS4="+$( tput cr 2> /dev/null;
193 | tput cuf 6 2> /dev/null;
194 | printf "%s" "$reset" )"
195 |
196 | export PS4
197 |
198 | }
199 |
200 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201 |
202 | main() {
203 | enable_color_support
204 | set_prompts
205 | }
206 |
207 | main
208 |
209 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210 |
211 | # Cleanup.
212 |
213 | unset -f enable_color_support
214 | unset -f main
215 | unset -f set_prompts
216 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [Cătălin][repo]’s dotfiles
2 |
3 | [![CI status for macOS][ci badge macos]][ci link macos]
4 | [![CI status for Ubuntu][ci badge ubuntu]][ci link ubuntu]
5 |
6 | These are the base dotfiles that I start with when I set up
7 | a new environment (for more specific local needs I use the
8 | [`*.local`](#local-settings) files).
9 |
10 | ## Table of Contents
11 |
12 | * [🔧 Setup](#setup)
13 | * [📸 Screenshots](#screenshots)
14 | * [🔁 Git](#git)
15 | * [⌨️ Vim](#vim)
16 | * [💄 Customize](#customize)
17 | * [🔀 Forks](#forks)
18 | * [🌐 Local Settings](#local-settings)
19 | * [🐚 `~/.bash.local`](#bashlocal)
20 | * [🔁 `~/.gitconfig.local`](#gitconfiglocal)
21 | * [⌨️ `~/.vimrc.local`](#vimrclocal)
22 | * [↕️ Update](#update)
23 | * [📑 License](#license)
24 |
25 | ## Setup
26 |
27 | To set up the dotfiles run the appropriate snippet in the terminal:
28 |
29 | > [!CAUTION]
30 | > __DO NOT__ run the setup script if you do not fully understand
31 | > [what it does][setup]. Seriously, __DON'T__!
32 |
33 | | OS | Snippet |
34 | |:---|:---|
35 | | macOS | `bash -c "$(curl -LsS https://raw.github.com/alrra/dotfiles/main/src/os/setup.sh)"` |
36 | | Ubuntu | `bash -c "$(wget -qO - https://raw.github.com/alrra/dotfiles/main/src/os/setup.sh)"` |
37 |
38 | That's it! ✨
39 |
40 | The setup process will:
41 |
42 | * Download the dotfiles on your computer
43 | (by default it will suggest `~/projects/dotfiles`).
44 | * [Symlink][symlink] the [Git], [shell], [tmux],
45 | and [Vim] related files.
46 | * Install applications / command-line tools for
47 | [macOS][install macos] / [Ubuntu][install ubuntu].
48 | * Set custom [macOS][preferences macos] /
49 | [Ubuntu][preferences ubuntu] preferences.
50 | * Install the [Vim][vim plugins] and
51 | [VS Code][vscode plugins] plugins.
52 |
53 | Setup process in action:
54 |
55 |
56 | | | |
57 | |:---:|:---:|
58 |
59 |
60 | ## Screenshots
61 |
62 | ### Git
63 |
64 | Output for `git status`:
65 |
66 | | ![Output for Git status on macOS][git output macos] | ![Output for Git status on Ubuntu][git output ubuntu] |
67 | |:---:|:---:|
68 | | macOS | Ubuntu |
69 |
70 | Output for `git log`:
71 |
72 | | ![Output for Git log on macOS][git log macos] | ![Output for Git log on Ubuntu][git log ubuntu] |
73 | |:---:|:---:|
74 | | macOS | Ubuntu |
75 |
76 | ### Vim
77 |
78 | | ![Vim on macOS][vim macos] | ![Vim on Ubuntu][vim ubuntu] |
79 | |:---:|:---:|
80 | | macOS | Ubuntu |
81 |
82 | ## Customize
83 |
84 | ### Local Settings
85 |
86 | The dotfiles can be easily extended to suit additional local
87 | requirements by using the following files:
88 |
89 | #### `~/.bash.local`
90 |
91 | The `~/.bash.local` file will be automatically sourced after all
92 | the other [Bash related files][shell], thus, allowing its content
93 | to add to or overwrite the existing aliases, settings, `PATH`, etc.
94 |
95 | Here is an example:
96 |
97 | ```shell
98 | #!/bin/bash
99 |
100 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 |
102 | # Set PATH additions.
103 |
104 | PATH="/Users/alrra/projects/dotfiles/src/bin/:$PATH"
105 |
106 | export PATH
107 |
108 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109 |
110 | # Set local aliases.
111 |
112 | alias g="git"
113 | ```
114 |
115 | #### `~/.gitconfig.local`
116 |
117 | The `~/.gitconfig.local` file will be automatically included after
118 | the configurations from `~/.gitconfig`, thus, allowing its content
119 | to overwrite or add to the existing Git configurations.
120 |
121 | __Note:__ Use `~/.gitconfig.local` to store sensitive information
122 | such as the Git user credentials, e.g.:
123 |
124 | ```gitconfig
125 | [commit]
126 |
127 | # Sign commits using GPG.
128 | # https://help.github.com/articles/signing-commits-using-gpg/
129 |
130 | gpgSign = true
131 |
132 | [user]
133 |
134 | name = Your Name
135 | email = account@example.com
136 | signingKey = XXXXXXXX
137 | ```
138 |
139 | #### `~/.vimrc.local`
140 |
141 | The `~/.vimrc.local` file will be automatically sourced after
142 | `~/.vimrc`, thus, allowing its content to add or overwrite the
143 | settings from `~/.vimrc`.
144 |
145 | Here is an example:
146 |
147 | ```vim
148 | " Disable arrow keys in insert mode.
149 |
150 | inoremap :echoe "Use j"
151 | inoremap :echoe "Use h"
152 | inoremap :echoe "Use l"
153 | inoremap :echoe "Use k"
154 |
155 | " Disable arrow keys in normal mode.
156 |
157 | nnoremap :echoe "Use j"
158 | nnoremap :echoe "Use h"
159 | nnoremap :echoe "Use l"
160 | nnoremap :echoe "Use k"
161 | ```
162 |
163 | ### Forks
164 |
165 | If you decide to [fork] this project, do not forget to substitute
166 | my username with your own in the [setup snippets](#setup) and [in
167 | the setup script][setup script].
168 |
169 | ## Update
170 |
171 | To update the dotfiles you can either run the [setup script][setup]
172 | or, if you want to update one particular part, run the appropriate
173 | [os script](src/os).
174 |
175 | ## License
176 |
177 | The code is available under the [MIT license][license].
178 |
179 |
180 |
181 | [ci badge macos]: https://github.com/alrra/dotfiles/workflows/macOS/badge.svg
182 | [ci badge ubuntu]: https://github.com/alrra/dotfiles/workflows/Ubuntu/badge.svg
183 | [ci link macos]: https://github.com/alrra/dotfiles/actions?query=workflow%3AmacOS
184 | [ci link ubuntu]: https://github.com/alrra/dotfiles/actions?query=workflow%3AUbuntu
185 | [fork]: https://help.github.com/en/github/getting-started-with-github/fork-a-repo
186 | [git log macos]: https://user-images.githubusercontent.com/1223565/101947422-519fc580-3ba5-11eb-90bc-1438072a45e1.png
187 | [git log ubuntu]: https://user-images.githubusercontent.com/1223565/101947420-51072f00-3ba5-11eb-9061-efb30ace1c21.png
188 | [git output macos]: https://user-images.githubusercontent.com/1223565/101947419-51072f00-3ba5-11eb-9e8e-fea987ac97c2.png
189 | [git output ubuntu]: https://user-images.githubusercontent.com/1223565/101947417-506e9880-3ba5-11eb-805c-0732602c34b3.png
190 | [Git]: src/git
191 | [install macos]: src/os/installs/macos
192 | [install ubuntu]: src/os/installs/ubuntu
193 | [license]: LICENSE.txt
194 | [preferences macos]: src/os/preferences/macos
195 | [preferences ubuntu]: src/os/preferences/ubuntu
196 | [repo]: https://github.com/alrra
197 | [setup script]: https://github.com/alrra/dotfiles/blob/main/src/os/setup.sh#L3
198 | [setup]: src/os/setup.sh
199 | [shell]: src/shell
200 | [symlink]: src/os/create_symbolic_links.sh
201 | [tmux]: src/tmux
202 | [vim macos]: https://user-images.githubusercontent.com/1223565/101947425-52385c00-3ba5-11eb-9a2a-13e7910d3673.png
203 | [vim plugins]: src/vim/vim/pack/minpac/start
204 | [vim ubuntu]: https://user-images.githubusercontent.com/1223565/101947424-519fc580-3ba5-11eb-83b1-e4c3573315a3.png
205 | [Vim]: src/vim
206 | [vscode plugins]: src/os/installs/macos/vscode.sh
207 |
--------------------------------------------------------------------------------
/src/os/preferences/macos/Solarized Dark.terminal:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | BackgroundBlur
6 | 0.0
7 | BackgroundColor
8 |
9 | YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
10 | AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEC0w
11 | LjAxNTI0OTAxNzI5IDAuMTI0MzYzMzMxMiAwLjE1OTY5NjAxMjcgMC45NwAQAYAC0hAR
12 | EhNaJGNsYXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXll
13 | ZEFyY2hpdmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KSlJabpq+3usPV2N0AAAAAAAAB
14 | AQAAAAAAAAAZAAAAAAAAAAAAAAAAAAAA3w==
15 |
16 | BlinkText
17 |
18 | CursorColor
19 |
20 | YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
21 | AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
22 | LjQ0MDU4MDI0ODggMC41MDk2MjkzMDkyIDAuNTE2ODU3OTgxNwAQAYAC0hAREhNaJGNs
23 | YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
24 | dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
25 | AAAZAAAAAAAAAAAAAAAAAAAA2Q==
26 |
27 | Font
28 |
29 | YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
30 | AAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5TU2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNs
31 | YXNzI0AwAAAAAAAAEBCAAoADXU1lbmxvLVJlZ3VsYXLSExQVFlokY2xhc3NuYW1lWCRj
32 | bGFzc2VzVk5TRm9udKIVF1hOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEaG1Ryb290
33 | gAEIERojLTI3PEJLUltiaXJ0dniGi5afpqmyxMfMAAAAAAAAAQEAAAAAAAAAHAAAAAAA
34 | AAAAAAAAAAAAAM4=
35 |
36 | FontAntialias
37 |
38 | FontHeightSpacing
39 | 1
40 | FontWidthSpacing
41 | 1
42 | ProfileCurrentVersion
43 | 2.06
44 | SelectionColor
45 |
46 | YnBsaXN0MDDUAQIDBAUGKyxYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
47 | AAGGoKcHCBMZHSQoVSRudWxs1QkKCwwNDg8QERJcTlNDb21wb25lbnRzVU5TUkdCXE5T
48 | Q29sb3JTcGFjZV8QEk5TQ3VzdG9tQ29sb3JTcGFjZVYkY2xhc3NPEB8wLjM2NzI1OTQx
49 | MTggMC4xMTU0Mzg3Mzk4IDEgMC42TxAVMC4zMTg4MDgzNzY4IDAgMSAwLjYAEAGAAoAG
50 | 0xQNFRYXGFVOU0lDQ1lOU1NwYWNlSUSAA4AFEAzSGg0bHFdOUy5kYXRhTxECJAAAAiRh
51 | cHBsBAAAAG1udHJSR0IgWFlaIAfhAAcABwANABYAIGFjc3BBUFBMAAAAAEFQUEwAAAAA
52 | AAAAAAAAAAAAAAAAAAD21gABAAAAANMtYXBwbMoalYIlfxBNOJkT1dHqFYIAAAAAAAAA
53 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACmRlc2MAAAD8AAAAZWNwcnQAAAFkAAAAI3d0
54 | cHQAAAGIAAAAFHJYWVoAAAGcAAAAFGdYWVoAAAGwAAAAFGJYWVoAAAHEAAAAFHJUUkMA
55 | AAHYAAAAIGNoYWQAAAH4AAAALGJUUkMAAAHYAAAAIGdUUkMAAAHYAAAAIGRlc2MAAAAA
56 | AAAAC0Rpc3BsYXkgUDMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
57 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAdGV4dAAA
58 | AABDb3B5cmlnaHQgQXBwbGUgSW5jLiwgMjAxNwAAWFlaIAAAAAAAAPNRAAEAAAABFsxY
59 | WVogAAAAAAAAg98AAD2/////u1hZWiAAAAAAAABKvwAAsTcAAAq5WFlaIAAAAAAAACg4
60 | AAARCwAAyLlwYXJhAAAAAAADAAAAAmZmAADypwAADVkAABPQAAAKW3NmMzIAAAAAAAEM
61 | QgAABd7///MmAAAHkwAA/ZD///ui///9owAAA9wAAMBugATSHh8gIVokY2xhc3NuYW1l
62 | WCRjbGFzc2VzXU5TTXV0YWJsZURhdGGjICIjVk5TRGF0YVhOU09iamVjdNIeHyUmXE5T
63 | Q29sb3JTcGFjZaInI1xOU0NvbG9yU3BhY2XSHh8pKldOU0NvbG9yoikjXxAPTlNLZXll
64 | ZEFyY2hpdmVy0S0uVHJvb3SAAQAIABEAGgAjAC0AMgA3AD8ARQBQAF0AYwBwAIUAjACu
65 | AMYAyADKAMwA0wDZAOMA5QDnAOkA7gD2Ax4DIAMlAzADOQNHA0sDUgNbA2ADbQNwA30D
66 | ggOKA40DnwOiA6cAAAAAAAACAQAAAAAAAAAvAAAAAAAAAAAAAAAAAAADqQ==
67 |
68 | ShowActiveProcessInTitle
69 |
70 | ShowCommandKeyInTitle
71 |
72 | ShowDimensionsInTitle
73 |
74 | ShowShellCommandInTitle
75 |
76 | ShowTTYNameInTitle
77 |
78 | ShowWindowSettingsNameInTitle
79 |
80 | TerminalType
81 | xterm-256color
82 | TextBoldColor
83 |
84 | YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
85 | AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECYw
86 | LjUwNTk5MTkzNTcgMC41NjQ4NTgzNzcgMC41NjM2MzY1NDE0ABABgALSEBESE1okY2xh
87 | c3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
88 | ZXLRFxhUcm9vdIABCBEaIy0yNztBSE5bYouNj5SfqLCzvM7R1gAAAAAAAAEBAAAAAAAA
89 | ABkAAAAAAAAAAAAAAAAAAADY
90 |
91 | TextColor
92 |
93 | YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
94 | AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
95 | LjQ0MDU4MDI0ODggMC41MDk2MjkzMDkyIDAuNTE2ODU3OTgxNwAQAYAC0hAREhNaJGNs
96 | YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
97 | dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
98 | AAAZAAAAAAAAAAAAAAAAAAAA2Q==
99 |
100 | UseBrightBold
101 |
102 | blackColour
103 |
104 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
105 | ZmZmg7JNIT2DkvUjPoO+F0s+AYY=
106 |
107 | blueColour
108 |
109 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
110 | ZmZmgyqcAj6DtOHsPoO+RUg/AYY=
111 |
112 | brightBlackColour
113 |
114 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
115 | ZmZmg+ZzgjyDs44BPoNahyM+AYY=
116 |
117 | brightBlueColour
118 |
119 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
120 | ZmZmg7yT4T6DEXcCP4POUAQ/AYY=
121 |
122 | brightCyanColour
123 |
124 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
125 | ZmZmg7CIAT+Dj5oQP4N8ShA/AYY=
126 |
127 | brightGreenColour
128 |
129 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
130 | ZmZmgzyujT6DFZy2PoOYFsQ+AYY=
131 |
132 | brightMagentaColour
133 |
134 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
135 | ZmZmgxMjsj6D+uazPoNkyTc/AYY=
136 |
137 | brightRedColour
138 |
139 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
140 | ZmZmgyfkPT+D/15aPoMgl5Y9AYY=
141 |
142 | brightWhiteColour
143 |
144 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
145 | ZmZmg49LfT+D0Dt1P4MGM10/AYY=
146 |
147 | brightYellowColour
148 |
149 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
150 | ZmZmg1MTpj6DeHnQPoPQg+A+AYY=
151 |
152 | cyanColour
153 |
154 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
155 | ZmZmg4VRFj6DfyESP4PkZwY/AYY=
156 |
157 | greenColour
158 |
159 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
160 | ZmZmg9lI5j6DIYkKP4PVjKU8AYY=
161 |
162 | magentaColour
163 |
164 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
165 | ZmZmg/4CRz+DBTzdPYMgzt4+AYY=
166 |
167 | name
168 | Solarized Dark
169 | redColour
170 |
171 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
172 | ZmZmg6i7UT+DUATePYMl2hA+AYY=
173 |
174 | shellExitAction
175 | 1
176 | type
177 | Window Settings
178 | whiteColour
179 |
180 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
181 | ZmZmgzqGaj+D2tdjP4NYPUw/AYY=
182 |
183 | yellowColour
184 |
185 | BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
186 | ZmZmg0DAJT+DB17vPoM4Y8A8AYY=
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/src/os/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | declare -r GITHUB_REPOSITORY="alrra/dotfiles"
4 |
5 | declare -r DOTFILES_ORIGIN="git@github.com:$GITHUB_REPOSITORY.git"
6 | declare -r DOTFILES_TARBALL_URL="https://github.com/$GITHUB_REPOSITORY/tarball/main"
7 | declare -r DOTFILES_UTILS_URL="https://raw.githubusercontent.com/$GITHUB_REPOSITORY/main/src/os/utils.sh"
8 |
9 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 |
11 | declare dotfilesDirectory="$HOME/projects/dotfiles"
12 | declare skipQuestions=false
13 |
14 | # ----------------------------------------------------------------------
15 | # | Helper Functions |
16 | # ----------------------------------------------------------------------
17 |
18 | download() {
19 |
20 | local url="$1"
21 | local output="$2"
22 |
23 | if command -v "curl" &> /dev/null; then
24 |
25 | curl \
26 | --location \
27 | --silent \
28 | --show-error \
29 | --output "$output" \
30 | "$url" \
31 | &> /dev/null
32 |
33 | return $?
34 |
35 | elif command -v "wget" &> /dev/null; then
36 |
37 | wget \
38 | --quiet \
39 | --output-document="$output" \
40 | "$url" \
41 | &> /dev/null
42 |
43 | return $?
44 | fi
45 |
46 | return 1
47 |
48 | }
49 |
50 | download_dotfiles() {
51 |
52 | local tmpFile=""
53 |
54 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 |
56 | print_in_purple "\n • Download and extract archive\n\n"
57 |
58 | tmpFile="$(mktemp /tmp/XXXXX)"
59 |
60 | download "$DOTFILES_TARBALL_URL" "$tmpFile"
61 | print_result $? "Download archive" "true"
62 | printf "\n"
63 |
64 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65 |
66 | if ! $skipQuestions; then
67 |
68 | ask_for_confirmation "Do you want to store the dotfiles in '$dotfilesDirectory'?"
69 |
70 | if ! answer_is_yes; then
71 | dotfilesDirectory=""
72 | while [ -z "$dotfilesDirectory" ]; do
73 | ask "Please specify another location for the dotfiles (path): "
74 | dotfilesDirectory="$(get_answer)"
75 | done
76 | fi
77 |
78 | # Ensure the `dotfiles` directory is available
79 |
80 | while [ -e "$dotfilesDirectory" ]; do
81 | ask_for_confirmation "'$dotfilesDirectory' already exists, do you want to overwrite it?"
82 | if answer_is_yes; then
83 | rm -rf "$dotfilesDirectory"
84 | break
85 | else
86 | dotfilesDirectory=""
87 | while [ -z "$dotfilesDirectory" ]; do
88 | ask "Please specify another location for the dotfiles (path): "
89 | dotfilesDirectory="$(get_answer)"
90 | done
91 | fi
92 | done
93 |
94 | printf "\n"
95 |
96 | else
97 |
98 | rm -rf "$dotfilesDirectory" &> /dev/null
99 |
100 | fi
101 |
102 | mkdir -p "$dotfilesDirectory"
103 | print_result $? "Create '$dotfilesDirectory'" "true"
104 |
105 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106 |
107 | # Extract archive in the `dotfiles` directory.
108 |
109 | extract "$tmpFile" "$dotfilesDirectory"
110 | print_result $? "Extract archive" "true"
111 |
112 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113 |
114 | rm -rf "$tmpFile"
115 | print_result $? "Remove archive"
116 |
117 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118 |
119 | cd "$dotfilesDirectory/src/os" \
120 | || return 1
121 |
122 | }
123 |
124 | download_utils() {
125 |
126 | local tmpFile=""
127 |
128 | tmpFile="$(mktemp /tmp/XXXXX)"
129 |
130 | download "$DOTFILES_UTILS_URL" "$tmpFile" \
131 | && . "$tmpFile" \
132 | && rm -rf "$tmpFile" \
133 | && return 0
134 |
135 | return 1
136 |
137 | }
138 |
139 | extract() {
140 |
141 | local archive="$1"
142 | local outputDir="$2"
143 |
144 | if command -v "tar" &> /dev/null; then
145 |
146 | tar \
147 | --extract \
148 | --gzip \
149 | --file "$archive" \
150 | --strip-components 1 \
151 | --directory "$outputDir"
152 |
153 | return $?
154 | fi
155 |
156 | return 1
157 |
158 | }
159 |
160 | verify_os() {
161 |
162 | declare -r MINIMUM_MACOS_VERSION="10.14"
163 | declare -r MINIMUM_UBUNTU_VERSION="24.04"
164 |
165 | local os_name="$(get_os)"
166 | local os_version="$(get_os_version)"
167 |
168 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169 |
170 | # Check if the OS is `macOS` and
171 | # it's above the required version.
172 |
173 | if [ "$os_name" == "macos" ]; then
174 |
175 | if is_supported_version "$os_version" "$MINIMUM_MACOS_VERSION"; then
176 | return 0
177 | else
178 | printf "Sorry, this script is intended only for macOS %s+" "$MINIMUM_MACOS_VERSION"
179 | fi
180 |
181 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182 |
183 | # Check if the OS is `Ubuntu` and
184 | # it's above the required version.
185 |
186 | elif [ "$os_name" == "ubuntu" ]; then
187 |
188 | if is_supported_version "$os_version" "$MINIMUM_UBUNTU_VERSION"; then
189 | return 0
190 | else
191 | printf "Sorry, this script is intended only for Ubuntu %s+" "$MINIMUM_UBUNTU_VERSION"
192 | fi
193 |
194 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
195 |
196 | else
197 | printf "Sorry, this script is intended only for macOS and Ubuntu!"
198 | fi
199 |
200 | return 1
201 |
202 | }
203 |
204 | # ----------------------------------------------------------------------
205 | # | Main |
206 | # ----------------------------------------------------------------------
207 |
208 | main() {
209 |
210 | # Ensure that the following actions
211 | # are made relative to this file's path.
212 |
213 | cd "$(dirname "${BASH_SOURCE[0]}")" \
214 | || exit 1
215 |
216 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
217 |
218 | # Load utils
219 |
220 | if [ -x "utils.sh" ]; then
221 | . "utils.sh" || exit 1
222 | else
223 | download_utils || exit 1
224 | fi
225 |
226 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
227 |
228 | # Ensure the OS is supported and
229 | # it's above the required version.
230 |
231 | verify_os \
232 | || exit 1
233 |
234 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
235 |
236 | skip_questions "$@" \
237 | && skipQuestions=true
238 |
239 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240 |
241 | ask_for_sudo
242 |
243 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
244 |
245 | # Check if this script was run directly (.//setup.sh),
246 | # and if not, it most likely means that the dotfiles were not
247 | # yet set up, and they will need to be downloaded.
248 |
249 | printf "%s" "${BASH_SOURCE[0]}" | grep "setup.sh" &> /dev/null \
250 | || download_dotfiles
251 |
252 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
253 |
254 | ./create_symbolic_links.sh "$@"
255 |
256 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
257 |
258 | ./create_local_config_files.sh
259 |
260 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
261 |
262 | ./installs/main.sh
263 |
264 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
265 |
266 | ./preferences/main.sh
267 |
268 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
269 |
270 | if cmd_exists "git"; then
271 |
272 | if [ "$(git config --get remote.origin.url)" != "$DOTFILES_ORIGIN" ]; then
273 | ./initialize_git_repository.sh "$DOTFILES_ORIGIN"
274 | fi
275 |
276 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
277 |
278 | if ! $skipQuestions; then
279 | ./update_content.sh
280 | fi
281 |
282 | fi
283 |
284 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
285 |
286 | if ! $skipQuestions; then
287 | ./restart.sh
288 | fi
289 |
290 | }
291 |
292 | main "$@"
293 |
--------------------------------------------------------------------------------
/src/os/utils.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | declare LOCAL_SHELL_CONFIG_FILE="$HOME/.bash.local"
4 |
5 | answer_is_yes() {
6 | [[ "$REPLY" =~ ^[Yy]$ ]] \
7 | && return 0 \
8 | || return 1
9 | }
10 |
11 | ask() {
12 | print_question "$1"
13 | read -r
14 | }
15 |
16 | ask_for_confirmation() {
17 | print_question "$1 (y/n) "
18 | read -r -n 1
19 | printf "\n"
20 | }
21 |
22 | ask_for_sudo() {
23 |
24 | # Ask for the administrator password upfront.
25 |
26 | sudo -v &> /dev/null
27 |
28 | # Update existing `sudo` time stamp
29 | # until this script has finished.
30 | #
31 | # https://gist.github.com/cowboy/3118588
32 |
33 | while true; do
34 | sudo -n true
35 | sleep 60
36 | kill -0 "$$" || exit
37 | done &> /dev/null &
38 |
39 | }
40 |
41 | cmd_exists() {
42 | command -v "$1" &> /dev/null
43 | }
44 |
45 | kill_all_subprocesses() {
46 |
47 | local i=""
48 |
49 | for i in $(jobs -p); do
50 | kill "$i"
51 | wait "$i" &> /dev/null
52 | done
53 |
54 | }
55 |
56 | execute() {
57 |
58 | local -r CMDS="$1"
59 | local -r MSG="${2:-$1}"
60 | local -r TMP_FILE="$(mktemp /tmp/XXXXX)"
61 |
62 | local exitCode=0
63 | local cmdsPID=""
64 |
65 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 |
67 | # If the current process is ended,
68 | # also end all its subprocesses.
69 |
70 | set_trap "EXIT" "kill_all_subprocesses"
71 |
72 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73 |
74 | # Execute commands in background
75 | # shellcheck disable=SC2261
76 |
77 | eval "$CMDS" \
78 | &> /dev/null \
79 | 2> "$TMP_FILE" &
80 |
81 | cmdsPID=$!
82 |
83 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84 |
85 | # Show a spinner if the commands
86 | # require more time to complete.
87 |
88 | show_spinner "$cmdsPID" "$CMDS" "$MSG"
89 |
90 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91 |
92 | # Wait for the commands to no longer be executing
93 | # in the background, and then get their exit code.
94 |
95 | wait "$cmdsPID" &> /dev/null
96 | exitCode=$?
97 |
98 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99 |
100 | # Print output based on what happened.
101 |
102 | print_result $exitCode "$MSG"
103 |
104 | if [ $exitCode -ne 0 ]; then
105 | print_error_stream < "$TMP_FILE"
106 | fi
107 |
108 | rm -rf "$TMP_FILE"
109 |
110 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111 |
112 | return $exitCode
113 |
114 | }
115 |
116 | get_answer() {
117 | printf "%s" "$REPLY"
118 | }
119 |
120 | get_os() {
121 |
122 | local os=""
123 | local kernelName=""
124 |
125 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126 |
127 | kernelName="$(uname -s)"
128 |
129 | if [ "$kernelName" == "Darwin" ]; then
130 | os="macos"
131 | elif [ "$kernelName" == "Linux" ] && \
132 | [ -e "/etc/os-release" ]; then
133 | os="$(. /etc/os-release; printf "%s" "$ID")"
134 | else
135 | os="$kernelName"
136 | fi
137 |
138 | printf "%s" "$os"
139 |
140 | }
141 |
142 | get_os_version() {
143 |
144 | local os=""
145 | local version=""
146 |
147 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148 |
149 | os="$(get_os)"
150 |
151 | if [ "$os" == "macos" ]; then
152 | version="$(sw_vers -productVersion)"
153 | elif [ -e "/etc/os-release" ]; then
154 | version="$(. /etc/os-release; printf "%s" "$VERSION_ID")"
155 | fi
156 |
157 | printf "%s" "$version"
158 |
159 | }
160 |
161 | is_git_repository() {
162 | git rev-parse &> /dev/null
163 | }
164 |
165 | is_supported_version() {
166 |
167 | # shellcheck disable=SC2206
168 | declare -a v1=(${1//./ })
169 | # shellcheck disable=SC2206
170 | declare -a v2=(${2//./ })
171 | local i=""
172 |
173 | # Fill empty positions in v1 with zeros.
174 | for (( i=${#v1[@]}; i<${#v2[@]}; i++ )); do
175 | v1[i]=0
176 | done
177 |
178 |
179 | for (( i=0; i<${#v1[@]}; i++ )); do
180 |
181 | # Fill empty positions in v2 with zeros.
182 | if [[ -z ${v2[i]} ]]; then
183 | v2[i]=0
184 | fi
185 |
186 | if (( 10#${v1[i]} < 10#${v2[i]} )); then
187 | return 1
188 | elif (( 10#${v1[i]} > 10#${v2[i]} )); then
189 | return 0
190 | fi
191 |
192 | done
193 |
194 | }
195 |
196 | mkd() {
197 | if [ -n "$1" ]; then
198 | if [ -e "$1" ]; then
199 | if [ ! -d "$1" ]; then
200 | print_error "$1 - a file with the same name already exists!"
201 | else
202 | print_success "$1"
203 | fi
204 | else
205 | execute "mkdir -p $1" "$1"
206 | fi
207 | fi
208 | }
209 |
210 | print_error() {
211 | print_in_red " [✖] $1 $2\n"
212 | }
213 |
214 | print_error_stream() {
215 | while read -r line; do
216 | print_error "↳ ERROR: $line"
217 | done
218 | }
219 |
220 | print_in_color() {
221 | printf "%b" \
222 | "$(tput setaf "$2" 2> /dev/null)" \
223 | "$1" \
224 | "$(tput sgr0 2> /dev/null)"
225 | }
226 |
227 | print_in_green() {
228 | print_in_color "$1" 2
229 | }
230 |
231 | print_in_purple() {
232 | print_in_color "$1" 5
233 | }
234 |
235 | print_in_red() {
236 | print_in_color "$1" 1
237 | }
238 |
239 | print_in_yellow() {
240 | print_in_color "$1" 3
241 | }
242 |
243 | print_question() {
244 | print_in_yellow " [?] $1"
245 | }
246 |
247 | print_result() {
248 |
249 | if [ "$1" -eq 0 ]; then
250 | print_success "$2"
251 | else
252 | print_error "$2"
253 | fi
254 |
255 | return "$1"
256 |
257 | }
258 |
259 | print_success() {
260 | print_in_green " [✔] $1\n"
261 | }
262 |
263 | print_warning() {
264 | print_in_yellow " [!] $1\n"
265 | }
266 |
267 | reload_local_shell_configs() {
268 | . "$LOCAL_SHELL_CONFIG_FILE"
269 | }
270 |
271 | set_trap() {
272 |
273 | trap -p "$1" | grep "$2" &> /dev/null \
274 | || trap '$2' "$1"
275 |
276 | }
277 |
278 | skip_questions() {
279 |
280 | while :; do
281 | case $1 in
282 | -y|--yes) return 0;;
283 | *) break;;
284 | esac
285 | shift 1
286 | done
287 |
288 | return 1
289 |
290 | }
291 |
292 | show_spinner() {
293 |
294 | local -r FRAMES='/-\|'
295 |
296 | # shellcheck disable=SC2034
297 | local -r NUMBER_OR_FRAMES=${#FRAMES}
298 |
299 | local -r CMDS="$2"
300 | local -r MSG="$3"
301 | local -r PID="$1"
302 |
303 | local i=0
304 | local frameText=""
305 |
306 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307 |
308 | # Note: In order for the Travis CI site to display
309 | # things correctly, it needs special treatment, hence,
310 | # the "is Travis CI?" checks.
311 |
312 | if [ "$TRAVIS" != "true" ]; then
313 |
314 | # Provide more space so that the text hopefully
315 | # doesn't reach the bottom line of the terminal window.
316 | #
317 | # This is a workaround for escape sequences not tracking
318 | # the buffer position (accounting for scrolling).
319 | #
320 | # See also: https://unix.stackexchange.com/a/278888
321 |
322 | printf "\n\n\n"
323 | tput cuu 3
324 |
325 | tput sc
326 |
327 | fi
328 |
329 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
330 |
331 | # Display spinner while the commands are being executed.
332 |
333 | while kill -0 "$PID" &>/dev/null; do
334 |
335 | frameText=" [${FRAMES:i++%NUMBER_OR_FRAMES:1}] $MSG"
336 |
337 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
338 |
339 | # Print frame text.
340 |
341 | if [ "$TRAVIS" != "true" ]; then
342 | printf "%s\n" "$frameText"
343 | else
344 | printf "%s" "$frameText"
345 | fi
346 |
347 | sleep 0.2
348 |
349 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
350 |
351 | # Clear frame text.
352 |
353 | if [ "$TRAVIS" != "true" ]; then
354 | tput rc
355 | else
356 | printf "\r"
357 | fi
358 |
359 | done
360 |
361 | }
362 |
363 | update_local_shell_configs() {
364 | declare -r LOCAL_SHELL_CONFIG_FILE="$HOME/.bash.local"
365 |
366 | if ! grep "$1" < "$LOCAL_SHELL_CONFIG_FILE" &> /dev/null; then
367 | execute \
368 | "printf '%s\n' '$1' >> $LOCAL_SHELL_CONFIG_FILE" \
369 | "Update '$LOCAL_SHELL_CONFIG_FILE'"
370 | fi
371 |
372 | reload_local_shell_configs
373 | }
374 |
--------------------------------------------------------------------------------
/src/git/gitconfig:
--------------------------------------------------------------------------------
1 | [alias]
2 |
3 | a = add
4 |
5 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6 |
7 | b = branch
8 |
9 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 |
11 | c = commit
12 |
13 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 |
15 | # Commit all changes.
16 |
17 | ca = !git add --all && git commit
18 |
19 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 |
21 | co = checkout
22 |
23 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24 |
25 | cp = cherry-pick
26 |
27 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28 |
29 | # Credit an author on the latest commit.
30 |
31 | credit = "!f() { \
32 | if [ -n \"$1\" ] && [ -n \"$2\" ]; then \
33 | git commit --amend --author \"$1 <$2>\" --no-edit --reuse-message=HEAD; \
34 | fi \
35 | }; f"
36 |
37 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38 |
39 | # Credit a co-author on the latest commit.
40 | #
41 | # https://help.github.com/en/articles/creating-a-commit-with-multiple-authors
42 | # https://help.github.com/en/articles/creating-a-commit-on-behalf-of-an-organization
43 |
44 | credit-co-author = "!f() { \
45 | if [ -n \"$1\" ] && [ -n \"$2\" ]; then \
46 | GIT_EDITOR=\"git interpret-trailers --in-place --trailer='Co-authored-by: $1 <$2>'\" git commit --amend; \
47 | fi \
48 | }; f"
49 |
50 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 |
52 | d = diff -- . ':!*package-lock.json' ':!*yarn.lock'
53 |
54 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 |
56 | dc = diff --cached -- . ':!*package-lock.json' ':!*yarn.lock'
57 |
58 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59 |
60 | f = fetch
61 |
62 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 |
64 | # Show custom text-based graphical log of the commit history.
65 |
66 | g = log --graph --pretty=custom
67 |
68 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69 |
70 | # Allow `$ git git git...`
71 |
72 | git = !exec git
73 |
74 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75 |
76 | # Show custom log of the commit history.
77 |
78 | l = log --pretty=custom
79 |
80 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 |
82 | # List contributors.
83 |
84 | lc = shortlog --email --numbered --summary
85 |
86 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 |
88 | # List remote branches.
89 |
90 | lrb = "!f() { \
91 | remote=\"${1:-origin}\"; \
92 | git ls-remote --heads \"$remote\"; \
93 | }; f"
94 |
95 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96 |
97 | # Merge GitHub pull request on top of the current branch or,
98 | # if a branch name is specified, on top of the specified branch.
99 |
100 | mpr = "!f() { \
101 | current_branch=\"$(git symbolic-ref --short HEAD)\"; \
102 | branch=\"${2:-$current_branch}\"; \
103 | \
104 | if [ $(printf \"%s\" \"$1\" | grep '^[0-9]\\+$' > /dev/null; printf $?) -eq 0 ]; then \
105 | git fetch origin refs/pull/$1/head:pr/$1 && \
106 | git checkout -B \"$branch\" && \
107 | git rebase pr/$1 && \
108 | git branch --delete --force pr/$1; \
109 | fi \
110 | }; f"
111 |
112 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113 |
114 | p = push
115 |
116 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117 |
118 | r = rebase
119 |
120 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
121 |
122 | # Remove the tag with the specified tag name if
123 | # exists and tag the latest commit with that name.
124 |
125 | retag = "!f() { \
126 | git tag --delete \"$1\" &> /dev/null; \
127 | git tag \"$1\"; \
128 | }; f"
129 |
130 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131 |
132 | # Remove last commits (by default it removes the last commit).
133 |
134 | rlc = "!f() { \
135 | number_of_commits=\"${1:-1}\"; \
136 | git reset --hard \"HEAD~$number_of_commits\"; \
137 | }; f"
138 |
139 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140 |
141 | s = status
142 |
143 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144 |
145 | # Search commits by source code.
146 |
147 | sc = "!f() { \
148 | git log --date=short --decorate --pretty=custom -S\"$1\"; \
149 | }; f"
150 |
151 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152 |
153 | # Seach commits by commit message.
154 |
155 | sm = "!f() { \
156 | git log --date=short --decorate --pretty=custom --grep=\"$1\"; \
157 | }; f"
158 |
159 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
160 |
161 | # Update the content of the last commit by including all
162 | # staged changes.
163 | #
164 | # Note: "Update" is used loosely. Git doesn't actually
165 | # update the last commit, but instead, creates a new commit
166 | # based on the last commit and replaces it.
167 |
168 | u = commit --amend --no-edit
169 |
170 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171 |
172 | # Update the content of the last commit by including all
173 | # local changes.
174 |
175 | ua = !git add --all && git commit --amend --no-edit
176 |
177 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
178 |
179 | # Undo last commits (by default it undoes the last commit).
180 |
181 | ulc = "!f() { \
182 | number_of_commits=\"${1:-1}\"; \
183 | git reset --soft \"HEAD~$number_of_commits\"; \
184 | }; f"
185 |
186 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
187 |
188 | # Update the content of the last commit by including all
189 | # staged changes as well as allow the user to change its
190 | # commit message.
191 |
192 | um = commit --amend
193 |
194 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
195 |
196 | # Start web-based visualizer.
197 |
198 | w = instaweb --httpd=webrick
199 |
200 | [color "branch"]
201 |
202 | current = green bold
203 | local = green
204 | remote = yellow
205 |
206 | [color "diff"]
207 |
208 | frag = magenta
209 | meta = yellow
210 |
211 | new = green
212 | old = red
213 |
214 | newMoved = cyan
215 | oldMoved = blue
216 |
217 | [color "status"]
218 |
219 | added = green reverse
220 | changed = yellow reverse
221 | untracked = red reverse
222 |
223 | [core]
224 |
225 | abbrev = 12
226 | attributesFile = ~/.gitattributes
227 | autocrlf = input
228 | editor = vim
229 | excludesFile = ~/.gitignore
230 |
231 | [diff]
232 |
233 | # Show blocks of moved text of at least 20
234 | # alphanumeric characters differently than adds/deletes.
235 | #
236 | # https://git-scm.com/docs/git-diff#git-diff-zebra
237 |
238 | colorMoved = zebra
239 |
240 | [diff "bin"]
241 |
242 | # Use `hexdump` to diff binary files.
243 |
244 | textconv = hexdump --canonical --no-squeezing
245 |
246 | [fetch]
247 |
248 | # Write a commit-graph after every `git fetch`
249 | # command that downloads a pack-file from a remote.
250 | #
251 | # For big repositories this helps speed up many
252 | # Git commands, especially log related operations.
253 |
254 | writeCommitGraph = true
255 |
256 | [help]
257 |
258 | # If a command is mistyped, make Git automatically
259 | # run the command it thinks the user wanted to type.
260 |
261 | autoCorrect = immediate
262 |
263 | [init]
264 |
265 | defaultBranch = main
266 |
267 | [pretty]
268 |
269 | custom = "%C(magenta)%h%C(red)%d %C(yellow)%ar %C(green)%s %C(yellow)(%an)"
270 | # │ │ │ │ └─ author name
271 | # │ │ │ └─ message
272 | # │ │ └─ date (relative)
273 | # │ └─ decorations (branch, heads or tags)
274 | # └─ hash (abbreviated)
275 |
276 |
277 | [push]
278 |
279 | # Make `git push` automatically push relevant
280 | # annotated tags when pushing branches out.
281 |
282 | followTags = true
283 |
284 | [rebase]
285 |
286 | # Automatically force-update any branches that
287 | # point to commits that are being rebased.
288 |
289 | updateRefs = true
290 |
291 | [user]
292 |
293 | # Do not guess the user's identity.
294 | # https://github.com/git/git/blob/90f7b16b3adc78d4bbabbd426fb69aa78c714f71/Documentation/config.txt#L2847-L2855
295 |
296 | useConfigOnly = true
297 |
298 | # [!] DO NOT store sensitive information such as the Git user
299 | # credentials (`name` / `email`), or things such as the `signingkey`
300 | # in this file, add them in `~/.gitconfig.local`!
301 | #
302 | # See also: https://github.com/alrra/dotfiles#gitconfiglocal
303 |
304 | [include]
305 |
306 | # Load local configs.
307 | # https://git-scm.com/docs/git-config#_includes
308 | #
309 | # [!] The following needs to remain at the end of this file in
310 | # order to allow any of the above configs to be overwritten
311 | # by the local ones
312 |
313 | path = ~/.gitconfig.local
314 |
--------------------------------------------------------------------------------
/src/shell/bash_functions:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4 |
5 | # Create data URI from a file.
6 |
7 | datauri() {
8 |
9 | local mimeType=""
10 |
11 | if [ ! -f "$1" ]; then
12 | printf "%s is not a file.\n" "$1"
13 | return
14 | fi
15 |
16 | mimeType=$(file --brief --mime-type "$1")
17 | # └─ do not prepend the filename to the output
18 |
19 | if [[ $mimeType == text/* ]]; then
20 | mimeType="$mimeType;charset=utf-8"
21 | fi
22 |
23 | printf "data:%s;base64,%s" \
24 | "$mimeType" \
25 | "$(openssl base64 -in "$1" | tr -d "\n")"
26 |
27 | }
28 |
29 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 |
31 | # Delete files that match a certain pattern from the current directory.
32 |
33 | delete-files() {
34 | local q="${1:-*.DS_Store}"
35 | find . -type f -name "$q" -ls -delete
36 | }
37 |
38 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 |
40 | # Execute Vim macro
41 |
42 | evm() {
43 |
44 | local numberOfTimes="${*: -1}"
45 | local files
46 |
47 | if [[ "$numberOfTimes" =~ ^[0-9]+$ ]]; then
48 | files=("${@:1:$#-1}")
49 | else
50 | numberOfTimes="1"
51 | files=("$@")
52 | fi
53 |
54 | for file in "${files[@]}"; do
55 | printf "* %s\n" "$file"
56 | vim \
57 | -c "norm! $numberOfTimes@q" \
58 | -c "wq" \
59 | "$file"
60 | done
61 |
62 | }
63 |
64 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65 |
66 | # Search history.
67 |
68 | h() {
69 | # ┌─ Enable colors for pipe.
70 | # │ ("--color=auto" enables colors only
71 | # │ if the output is in the terminal.)
72 | grep --color=always "$*" "$HISTFILE" \
73 | | less --no-init --raw-control-chars
74 | # │ └─ Display ANSI color escape sequences in raw form.
75 | # └─ Don't clear the screen after quitting less.
76 | }
77 |
78 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79 |
80 | # Optimize PDF files.
81 | #
82 | # Usage examples:
83 | #
84 | # optimize-pdfs path/to/some/directory path/to/some/file ...
85 |
86 | optimize-pdfs() (
87 |
88 | # Check if the pdfcpu command-line tool is installed.
89 |
90 | if ! command -v "pdfcpu" &> /dev/null; then
91 | printf "\n%s\n\n" "pdfcpu command-line tool is not installed!"
92 | exit
93 | fi
94 |
95 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96 |
97 | get-file-size() (
98 | printf "%s" "$(wc -c < "$1")"
99 | )
100 |
101 | optimize-pdf() (
102 | local filePath="$(dirname "${1%/}")"
103 | local fileName="_$(printf "%s" "$(basename "$1")" | tr '[:upper:]' '[:lower:]')"
104 |
105 | local optimizedFilePath="$filePath/$fileName"
106 |
107 | printf "* %s\n" "$1"
108 |
109 | pdfcpu optimize "$1" "$optimizedFilePath" &> /dev/null
110 | local exitCode=$?
111 |
112 | # If something went wrong (i.e. pdfcpu didn't create
113 | # the optimized file or exited with a non-zero status)
114 | # or the size of the optimized file is bigger than the
115 | # original file, keep the original file.
116 |
117 | if [ ! -f "$optimizedFilePath" ]; then
118 | return
119 | fi
120 |
121 | if [ $exitCode -ne 0 ] || \
122 | [ "$(get-file-size "$1")" -le "$(get-file-size "$optimizedFilePath")" ];
123 | then
124 | rm -rf "$optimizedFilePath"
125 | return
126 | fi
127 |
128 | # Otherwise, replace the original file with the optimized one.
129 |
130 | mv -f "$optimizedFilePath" "$1" 1> /dev/null
131 | )
132 |
133 | # ┌─ Default to the current directory.
134 | for filePath in "${@:-.}"; do
135 | if [ -d "$filePath" ]; then
136 | find "${filePath%/}" \
137 | -depth 1 \
138 | -name \*.pdf \
139 | -print \
140 | -type f \
141 | | while read -r file; do
142 | optimize-pdf "$file"
143 | done
144 | elif [ -f "$filePath" ]; then
145 | optimize-pdf "$filePath"
146 | fi
147 | done
148 | )
149 |
150 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
151 |
152 | # Rename media files.
153 | #
154 | # Rename the specified files so the filename is the file created date
155 | # in the following format:
156 | #
157 | # -- ..
158 | #
159 | # Usage examples:
160 | #
161 | # rename-media-files path/to/some/directory path/to/some/file ...
162 |
163 | rename-media-files() (
164 |
165 | rename_file() (
166 |
167 | filePath="$(dirname "${1%/}")"
168 | fileName="$(printf "%s" "$(basename "$1")" | tr '[:upper:]' '[:lower:]')"
169 | fileExtension="${fileName##*.}"
170 |
171 | # iOS
172 | #
173 | # * IMG_1234.PNG => 2020-05-05 05.05.05.png
174 |
175 | if [[ "$fileName" =~ ^img_[0-9]+ ]]; then
176 | newFileName="$(stat -f %SB -t "%Y-%m-%d %H.%M.%S" "$1")"
177 |
178 | # Handle the cases where multiple files have the same
179 | # creation date.
180 |
181 | index="$(find "$filePath" -maxdepth 1 -name "${newFileName}*" | wc -l | tr -d ' ')"
182 |
183 | if [ "$index" -gt 0 ]; then
184 | newFileName="$newFileName $index"
185 | fi
186 |
187 | mv "$1" "$filePath/$newFileName.$fileExtension"
188 | return
189 | fi
190 |
191 | # Other
192 | #
193 | # Files that already contain the created date in the filename,
194 | # but not in the intended format.
195 | #
196 | # * 20200505_050505.dng => 2020-05-05 05.05.05.dng
197 | # * Screenshot 2020-01-02 at 03.04.05.png => 2020-01-02 03-04-05.jpg
198 | # * Screenshot_20201010-101010_Something.jpg => 2020-10-10 10-10-10.jpg
199 | # * signal-2020-05-06-07-08-09-123.mp4 => 2020-05-06 07-08-09.mp4
200 |
201 | newFileName="$(printf "%s" "$fileName" | sed 's/[^0-9]*\([0-9]\{4\}\)[_-]\{0,1\}\([0-9]\{2\}\)[_-]\{0,1\}\([0-9]\{2\}\)[_-]\{0,1\}\( at \)\{0,1\}\([0-9]\{2\}\)[_.-]\{0,1\}\([0-9]\{2\}\)[_.-]\{0,1\}\([0-9]\{2\}\).*\(\..*\)$/\1-\2-\3 \5.\6.\7\8/')"
202 |
203 | if [ "$newFileName" != "$fileName" ]; then
204 | mv -f "$1" "$filePath/$newFileName"
205 | fi
206 | )
207 |
208 | # ┌─ Default to the current directory.
209 | for filePath in "${@:-.}"; do
210 | if [ -d "$filePath" ]; then
211 | find "${filePath%/}" \
212 | -type f \
213 | -depth 1 \
214 | -print \
215 | | while read -r file; do
216 | rename_file "$file"
217 | done
218 | elif [ -f "$filePath" ]; then
219 | rename_file "$filePath"
220 | fi
221 | done
222 |
223 | )
224 |
225 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
226 |
227 | # Resize image.
228 | #
229 | # Create a new image based on the specified image resized by the
230 | # specified amount.
231 | #
232 | # $1: Path to the original image.
233 | # $2: Resize value (default is '50%').
234 | # See also: https://imagemagick.org/script/command-line-processing.php#geometry
235 | #
236 | # Usage examples:
237 | #
238 | # * resize-image ./path/to/image.jpg 30%
239 | # * resize-image ./path/to/image.jpg 1000x1000!
240 |
241 | resize-image() {
242 |
243 | # Check if ImageMagick's `magick` command-line tool is installed.
244 |
245 | if ! command -v "magick" &> /dev/null; then
246 | printf "ImageMagick's 'magick' command-line tool is not installed!\n"
247 | return
248 | fi
249 |
250 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
251 |
252 | # Check if the file is an image file.
253 |
254 | if [ "$(file --mime-type --brief "$1" | cut -d'/' -f1)" != "image" ]; then
255 | printf "'%s' is not an image file.\n" "$1"
256 | return
257 | fi
258 |
259 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
260 |
261 | declare path="$(dirname "$1")"
262 | declare fileName="$(basename "$1")"
263 | declare geometry="${2:-50%}"
264 |
265 | magick \
266 | "$1" \
267 | -colorspace RGB \
268 | +sigmoidal-contrast 11.6933 \
269 | -define filter:filter=Sinc \
270 | -define filter:window=Jinc \
271 | -define filter:lobes=3 \
272 | -sigmoidal-contrast 11.6933 \
273 | -colorspace sRGB \
274 | -background transparent \
275 | -gravity center \
276 | -resize "$geometry" \
277 | +append \
278 | "$path/_$fileName" \
279 | && printf "* %s (%s)\n" \
280 | "$path/_$fileName" \
281 | "$geometry"
282 |
283 | }
284 |
285 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
286 |
287 | # Resize video.
288 | #
289 | # Create a new video based on the specified video resized by the
290 | # specified amount.
291 | #
292 | # $1: Path to the original video file.
293 | # $2: Resolution (default is '1920:1080').
294 | # $3: Start time (default is '00:00:00').
295 | # $4: Constant Rate Factor (default is '23').
296 | #
297 | # Usage examples:
298 | #
299 | # * resize-video ./path/to/video.mp4 "1080:1920" "00:00:01.500" "23"
300 |
301 | resize-video() {
302 |
303 | # Check if the `ffmpeg` command-line tool is installed.
304 |
305 | if ! command -v "ffmpeg" &> /dev/null; then
306 | printf "'ffmpeg' is not installed\n"
307 | return
308 | fi
309 |
310 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
311 |
312 | # Check if the file is a video file.
313 |
314 | if [ "$(file --mime-type --brief "$1" | cut -d'/' -f1)" != "video" ]; then
315 | printf "'%s' is not a video file.\n" "$1"
316 | return
317 | fi
318 |
319 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
320 |
321 | declare fileName="$(basename "$1")"
322 | declare filePath="$(dirname "${1%/}")"
323 | declare scale="${2:-1920:1080}"
324 | declare startTime=${3:-00:00:00}
325 | declare crf=${4:-23}
326 |
327 | declare outputFileName="$filePath/_${fileName%.*}.mp4"
328 |
329 |
330 | # The options used below try to offer a good balance between
331 | # cross-platform interoperability, quality, and file size.
332 |
333 | ffmpeg \
334 | -i "$1" \
335 | -ss "$startTime" \
336 | -acodec aac \
337 | -ac 2 \
338 | -strict -2 \
339 | -crf "$crf" \
340 | -nostdin \
341 | -preset veryslow \
342 | -vcodec libx264 \
343 | -vf "scale=${scale},setsar=1,format=yuv420p" \
344 | -y \
345 | "$outputFileName" \
346 | && printf "* %s / %s / %s\n" \
347 | "$outputFileName" \
348 | "$scale" \
349 | "$startTime"
350 |
351 | }
352 |
353 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
354 |
355 | # Search for text within the current directory.
356 |
357 | s() {
358 | grep --color=always "$*" \
359 | --exclude-dir=".git" \
360 | --exclude-dir="node_modules" \
361 | --ignore-case \
362 | --recursive \
363 | . \
364 | | less --no-init --raw-control-chars
365 | # │ └─ Display ANSI color escape sequences in raw form.
366 | # └─ Don't clear the screen after quitting less.
367 | }
368 |
--------------------------------------------------------------------------------
/src/vim/vimrc:
--------------------------------------------------------------------------------
1 | " ----------------------------------------------------------------------
2 | " | General Settings |
3 | " ----------------------------------------------------------------------
4 |
5 | " Don't make Vim vi-compatibile.
6 |
7 | set nocompatible
8 |
9 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 |
11 | " Enable syntax highlighting.
12 |
13 | syntax on
14 |
15 | if has('autocmd')
16 | filetype plugin indent on
17 | " │ │ └─ Enable file type detection.
18 | " │ └────── Enable loading of indent file.
19 | " └──────────── Enable loading of plugin files.
20 | endif
21 |
22 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 |
24 | " Copy indent to the new line.
25 |
26 | set autoindent
27 |
28 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 |
30 | " Allow backspace in insert mode.
31 |
32 | set backspace=indent
33 | set backspace+=eol
34 | set backspace+=start
35 |
36 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 |
38 | " Set directory for backup files.
39 |
40 | set backupdir=~/.vim/backups
41 |
42 | if has('wildignore')
43 |
44 | " Don't create backups for certain files.
45 |
46 | set backupskip='/tmp/*'
47 | set backupskip+='/private/tmp/*'
48 |
49 | endif
50 |
51 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 |
53 | " Use the system clipboard as the default register.
54 |
55 | set clipboard=unnamed
56 |
57 | if has('unnamedplus')
58 | set clipboard+=unnamedplus
59 | endif
60 |
61 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62 |
63 | " When making a change don't redisplay the line and
64 | " instead put a `$` sign at the end of the changed text.
65 |
66 | set cpoptions+=$
67 |
68 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69 |
70 | if has('syntax')
71 |
72 | " Highlight certain column(s).
73 | set colorcolumn=73
74 |
75 | " Highlight the current line.
76 | set cursorline
77 |
78 | endif
79 |
80 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 |
82 | " Set directory for swap files.
83 |
84 | set directory=~/.vim/swaps
85 |
86 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 |
88 | " Use UTF-8 without BOM.
89 |
90 | set encoding=utf-8 nobomb
91 |
92 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
93 |
94 | " Increase command line history.
95 |
96 | if has('cmdline_hist')
97 | set history=5000
98 | endif
99 |
100 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 |
102 | " Search settings.
103 |
104 | if has('extra_search')
105 |
106 | " Enable search highlighting.
107 | set hlsearch
108 |
109 | " Highlight search pattern as it is being typed.
110 | set incsearch
111 |
112 | endif
113 |
114 | " Ignore case in search patterns.
115 |
116 | set ignorecase
117 |
118 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119 |
120 | " Always show the status line.
121 |
122 | set laststatus=2
123 |
124 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125 |
126 | " Do not redraw the screen while executing macros,
127 | " registers, and other commands that have not been typed.
128 |
129 | set lazyredraw
130 |
131 |
132 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
133 |
134 | " Use custom symbols to represent invisible characters.
135 |
136 | set listchars=tab:▸\
137 | set listchars+=trail:·
138 | set listchars+=eol:↴
139 | set listchars+=nbsp:_
140 |
141 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
142 |
143 | " Enable extended regexp.
144 |
145 | set magic
146 |
147 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148 |
149 | " Hide mouse pointer while typing.
150 |
151 | set mousehide
152 |
153 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154 |
155 | " Disable error bells.
156 |
157 | set noerrorbells
158 |
159 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
160 |
161 | " When using the join command only insert a single
162 | " space after a `.`, `?`, or `!`.
163 |
164 | set nojoinspaces
165 |
166 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
167 |
168 | " Disable for security reasons.
169 | " https://github.com/numirias/security/blob/cf4f74e0c6c6e4bbd6b59823aa1b85fa913e26eb/doc/2019-06-04_ace-vim-neovim.md#readme
170 |
171 | set nomodeline
172 |
173 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
174 |
175 | " Kept the cursor on the same column.
176 |
177 | set nostartofline
178 |
179 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
180 |
181 | " Show line number.
182 |
183 | set number
184 |
185 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
186 |
187 | " Increase the minimal number of columns used for the `line number`.
188 |
189 | if has('linebreak')
190 | set numberwidth=5
191 | endif
192 |
193 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
194 |
195 | " Report the number of lines changed.
196 |
197 | set report=0
198 |
199 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
200 |
201 | " Show cursor position.
202 |
203 | if has('cmdline_info')
204 | set ruler
205 | endif
206 |
207 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
208 |
209 | " When scrolling keep the cursor 5 lines below
210 | " the top and 5 lines above the bottom of the screen.
211 |
212 | set scrolloff=5
213 |
214 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
215 |
216 | " Avoid all the hit-enter prompts.
217 |
218 | set shortmess=aAItW
219 |
220 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221 |
222 | " Show the command being typed.
223 |
224 | if has('cmdline_info')
225 | set showcmd
226 | endif
227 |
228 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 |
230 | " Show current mode.
231 |
232 | set showmode
233 |
234 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
235 |
236 | " Set the spellchecking language.
237 |
238 | if has('syntax')
239 | set spelllang=en_us
240 | endif
241 |
242 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
243 |
244 | " Override `ignorecase` option if the search pattern
245 | " contains uppercase characters.
246 |
247 | set smartcase
248 |
249 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
250 |
251 | " Limit syntax highlighting.
252 | " This avoids the very slow redrawing when files contain long lines.
253 |
254 | if has('syntax')
255 | set synmaxcol=2500
256 | endif
257 |
258 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
259 |
260 | " Set global settings.
261 |
262 | set tabstop=4
263 | set softtabstop=4
264 | set shiftwidth=4
265 | set expandtab
266 |
267 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
268 |
269 | " Enable fast terminal connection.
270 |
271 | set ttyfast
272 |
273 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
274 |
275 | if has('persistent_undo')
276 |
277 | " Set directory for undo files.
278 | set undodir=~/.vim/undos
279 |
280 | " Automatically save undo history.
281 | set undofile
282 |
283 | endif
284 |
285 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
286 |
287 | " Allow cursor to be anywhere.
288 |
289 | if has('virtualedit')
290 | set virtualedit=all
291 | endif
292 |
293 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
294 |
295 | " Disable beeping and window flashing.
296 | " https://vim.wikia.com/wiki/Disable_beeping
297 |
298 | set visualbell
299 | set noerrorbells
300 | set t_vb=
301 |
302 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
303 |
304 | " Enable enhanced command-line completion.
305 | "
306 | " By hitting in command mode, Vim will show the possible
307 | " matches just above the command line with the first match being
308 | " highlighted.
309 |
310 | if has('wildmenu')
311 | set wildmenu
312 | endif
313 |
314 |
315 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
316 |
317 | " Allow windows to be squashed.
318 |
319 | if has('windows')
320 | set winminheight=0
321 | endif
322 |
323 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
324 |
325 | " Prevent `Q` in `normal` mode from entering `Ex` mode.
326 |
327 | nmap Q
328 |
329 | " ----------------------------------------------------------------------
330 | " | Plugins |
331 | " ----------------------------------------------------------------------
332 |
333 | " Use `minpac` to manage the Vim plugins.
334 | " https://github.com/k-takata/minpac
335 |
336 | function! InitPlugins() abort
337 |
338 | packadd minpac
339 |
340 | call minpac#init()
341 | call minpac#add('k-takata/minpac', { 'type': 'opt' })
342 |
343 | call minpac#add('altercation/vim-colors-solarized')
344 | call minpac#add('ap/vim-css-color')
345 | call minpac#add('chrisbra/unicode.vim')
346 | call minpac#add('chrisbra/vim-xml-runtime')
347 | call minpac#add('godlygeek/tabular')
348 | call minpac#add('isRuslan/vim-es6')
349 | call minpac#add('jelera/vim-javascript-syntax')
350 | call minpac#add('ctrlpvim/ctrlp.vim')
351 | call minpac#add('marijnh/tern_for_vim', { 'do': ':silent ! cd $HOME/.vim/pack/minpac/start/tern_for_vim && npm i &> /dev/null' })
352 | call minpac#add('mattn/emmet-vim')
353 | call minpac#add('mattn/webapi-vim', { 'type': 'opt' })
354 | call minpac#add('mhinz/vim-signify')
355 | call minpac#add('moll/vim-node')
356 | call minpac#add('mtscout6/syntastic-local-eslint.vim')
357 | call minpac#add('nathanaelkane/vim-indent-guides')
358 | call minpac#add('raimondi/delimitmate')
359 | call minpac#add('scrooloose/nerdtree')
360 | call minpac#add('scrooloose/syntastic')
361 | call minpac#add('sheerun/vim-polyglot', { 'type': 'opt' })
362 | call minpac#add('thiagoalessio/rainbow_levels.vim')
363 | call minpac#add('tomtom/tcomment_vim')
364 | call minpac#add('tpope/vim-commentary')
365 | call minpac#add('tpope/vim-fugitive')
366 | call minpac#add('tpope/vim-repeat')
367 | call minpac#add('tpope/vim-surround')
368 | call minpac#add('tpope/vim-unimpaired')
369 | call minpac#add('wellle/targets.vim')
370 |
371 | endfunction
372 |
373 | silent! packadd webapi-vim
374 |
375 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
376 |
377 | " Define custom commands for managing plugins.
378 |
379 | command! PluginsClean call InitPlugins() | call minpac#clean()
380 | command! PluginsSetup call InitPlugins() | call minpac#update('', { 'do': 'qall' })
381 | command! PluginsStatus call InitPlugins() | call minpac#status()
382 | command! PluginsUpdate call InitPlugins() | call minpac#update('', { 'do': 'call minpac#status() | qall' })
383 |
384 | " ----------------------------------------------------------------------
385 | " | Plugins - Emmet |
386 | " ----------------------------------------------------------------------
387 |
388 | " Redefine trigger key.
389 |
390 | let g:user_emmet_leader_key=","
391 |
392 | " Only enable normal mode functions.
393 |
394 | let g:user_emmet_mode='a'
395 |
396 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
397 |
398 | " Load custom snippets.
399 |
400 | if &runtimepath =~ 'webapi-vim'
401 | let g:user_emmet_settings = webapi#json#decode(join(readfile(expand("~/.vim/snippets/emmet.json")), "\n"))
402 | endif
403 |
404 |
405 | " ----------------------------------------------------------------------
406 | " | Plugins - Indent Guides |
407 | " ----------------------------------------------------------------------
408 |
409 | " Set custom indent colors.
410 | " https://github.com/nathanaelkane/vim-indent-guides#setting-custom-indent-colors
411 |
412 | let g:indent_guides_auto_colors = 0
413 |
414 | autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd
415 | \ guibg=#00323D
416 | \ ctermbg=Magenta
417 |
418 | autocmd VimEnter,Colorscheme * :hi IndentGuidesEven
419 | \ guibg=#073642
420 | \ ctermbg=DarkMagenta
421 |
422 |
423 | " ----------------------------------------------------------------------
424 | " | Plugins - Markdown |
425 | " ----------------------------------------------------------------------
426 |
427 | " Disable Folding.
428 | " https://github.com/plasticboy/vim-markdown#disable-folding
429 |
430 | let g:vim_markdown_folding_disabled=1
431 |
432 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
433 |
434 | " Make `Tab` autocomplete.
435 |
436 | inoremap pumvisible() ? "\" : "\"
437 |
438 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
439 |
440 | " Make `Shift+Tab` insert `Tab` character.
441 |
442 | inoremap
443 |
444 | " ----------------------------------------------------------------------
445 | " | Plugins - Signify |
446 | " ----------------------------------------------------------------------
447 |
448 | " Disable Signify by default.
449 | " https://github.com/mhinz/vim-signify
450 |
451 | let g:signify_disable_by_default=1
452 |
453 |
454 | " ----------------------------------------------------------------------
455 | " | Plugins - Syntastic |
456 | " ----------------------------------------------------------------------
457 |
458 | " Inform Syntastic which checkers to use based on file types.
459 | " https://github.com/scrooloose/syntastic#faq
460 |
461 | let g:syntastic_javascript_checkers = [ 'eslint' ]
462 |
463 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
464 |
465 | " Disable syntax checking by default.
466 |
467 | let g:syntastic_mode_map = {
468 | \ "active_filetypes": [],
469 | \ "mode": "passive",
470 | \ "passive_filetypes": []
471 | \}
472 |
473 |
474 | " ----------------------------------------------------------------------
475 | " | Helper Functions |
476 | " ----------------------------------------------------------------------
477 |
478 | function! GetGitBranchName()
479 |
480 | let branchName = ""
481 |
482 | if exists("g:loaded_fugitive")
483 | let branchName = "[" . fugitive#Head() . "]"
484 | endif
485 |
486 | return branchName
487 |
488 | endfunction
489 |
490 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
491 |
492 | function! PrettyPrint()
493 |
494 | if ( &filetype == 'json' && (has('python3') || has('python')) )
495 | %!python -m json.tool
496 | norm! ggVG==
497 | elseif ( &filetype == 'svg' || &filetype == 'xml' )
498 | set formatexpr=xmlformat#Format()
499 | norm! Vgq
500 | endif
501 |
502 | endfunction
503 |
504 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
505 |
506 | function! StripBOM()
507 | if has('multi_byte')
508 | set nobomb
509 | endif
510 | endfunction
511 |
512 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
513 |
514 | function! StripTrailingWhitespaces()
515 |
516 | " Save last search and cursor position.
517 |
518 | let searchHistory = @/
519 | let cursorLine = line(".")
520 | let cursorColumn = col(".")
521 |
522 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
523 |
524 | " Strip trailing whitespaces.
525 |
526 | %s/\s\+$//e
527 |
528 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
529 |
530 | " Restore previous search history and cursor position.
531 |
532 | let @/ = searchHistory
533 | call cursor(cursorLine, cursorColumn)
534 |
535 |
536 | endfunction
537 |
538 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
539 |
540 | function! ToggleLimits()
541 |
542 | " [51,73]
543 | "
544 | " * Git commit message
545 | " http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
546 | "
547 | " [81]
548 | "
549 | " * general use
550 | " https://daniel.haxx.se/blog/2020/11/30/i-am-an-80-column-purist/
551 |
552 | if ( &colorcolumn == "73" )
553 | set colorcolumn+=51,81
554 | else
555 | set colorcolumn-=51,81
556 | endif
557 |
558 | endfunction
559 |
560 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
561 |
562 | function! ToggleRelativeLineNumbers()
563 |
564 | if ( &relativenumber == 1 )
565 | set number
566 | else
567 | set relativenumber
568 | endif
569 |
570 | endfunction
571 |
572 |
573 | " ----------------------------------------------------------------------
574 | " | Automatic Commands |
575 | " ----------------------------------------------------------------------
576 |
577 | if has("autocmd")
578 |
579 | " Autocommand Groups.
580 | " http://learnvimscriptthehardway.stevelosh.com/chapters/14.html
581 |
582 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
583 |
584 | " Automatically reload the configurations from
585 | " the `~/.vimrc` file whenever they are changed.
586 |
587 | augroup auto_reload_vim_configs
588 |
589 | autocmd!
590 | autocmd BufWritePost vimrc source $MYVIMRC
591 |
592 | augroup END
593 |
594 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
595 |
596 | " Correctly recognize files.
597 |
598 | augroup correctly_recognize_files
599 |
600 | autocmd!
601 | autocmd BufEnter gitconfig :setlocal filetype=gitconfig
602 | autocmd BufEnter .gitconfig.local :setlocal filetype=gitconfig
603 |
604 | augroup END
605 |
606 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
607 |
608 | " Use relative line numbers.
609 | " http://jeffkreeftmeijer.com/2012/relative-line-numbers-in-vim-for-super-fast-movement/
610 |
611 | augroup relative_line_numbers
612 |
613 | autocmd!
614 |
615 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
616 |
617 | " Automatically switch to absolute
618 | " line numbers when Vim loses focus.
619 |
620 | autocmd FocusLost * :set number
621 |
622 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
623 |
624 | " Automatically switch to relative
625 | " line numbers when Vim gains focus.
626 |
627 | autocmd FocusGained * :set relativenumber
628 |
629 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
630 |
631 | " Automatically switch to absolute
632 | " line numbers when Vim is in insert mode.
633 |
634 | autocmd InsertEnter * :set number
635 |
636 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
637 |
638 | " Automatically switch to relative
639 | " line numbers when Vim is in normal mode.
640 |
641 | autocmd InsertLeave * :set relativenumber
642 |
643 |
644 | augroup END
645 |
646 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
647 |
648 | " Automatically strip whitespaces when files are saved.
649 |
650 | augroup strip_whitespaces
651 |
652 | " List of file types for which the whitespaces
653 | " should not be removed:
654 |
655 | let excludedFileTypes = []
656 |
657 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
658 |
659 | " Only strip the whitespaces if the file type is not
660 | " in the excluded list.
661 |
662 | autocmd!
663 | autocmd BufWritePre * if index(excludedFileTypes, &ft) < 0 |
664 | \ :call StripBOM() |
665 | \ :call StripTrailingWhitespaces()
666 |
667 | augroup END
668 |
669 | endif
670 |
671 |
672 | " ----------------------------------------------------------------------
673 | " | Color Scheme |
674 | " ----------------------------------------------------------------------
675 |
676 | " Enable full-color support.
677 |
678 | set t_Co=256
679 |
680 | " Use colors that look good on a dark background.
681 |
682 | set background=dark
683 |
684 |
685 | " Set custom configurations for when the
686 | " Solarized theme is used from Vim's Terminal mode.
687 | "
688 | " https://github.com/altercation/vim-colors-solarized
689 |
690 | if !has("gui_running")
691 | let g:solarized_contrast = "high"
692 | let g:solarized_termcolors = 256
693 | let g:solarized_termtrans = 1
694 | let g:solarized_visibility = "high"
695 | endif
696 |
697 | silent! colorscheme solarized " Use custom color scheme.
698 |
699 | " ----------------------------------------------------------------------
700 | " | Key Mappings |
701 | " ----------------------------------------------------------------------
702 |
703 | " Use a different mapleader (default is "\").
704 |
705 | let mapleader = ","
706 |
707 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
708 |
709 | " [,* ] Search and replace the word under the cursor.
710 |
711 | nmap * :%s/\<\>//
712 |
713 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
714 |
715 | " [,cc ] Toggle code comments.
716 | " https://github.com/tomtom/tcomment_vim
717 |
718 | map cc :TComment
719 |
720 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
721 |
722 | " [,cr ] Calculate result.
723 | " http://vimcasts.org/e/56
724 |
725 | nmap cr 0yt=A="
726 |
727 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
728 |
729 | " [,cs ] Clear search.
730 |
731 | map cs :noh
732 |
733 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
734 |
735 | " [,gd ] Toggle Git differences.
736 |
737 | map gd :SignifyToggle
738 |
739 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
740 |
741 | " [,ffu] Convert file to use Unix line endings.
742 | " See also: https://vim.fandom.com/wiki/File_format
743 |
744 | map ffu :edit ++fileformat=dos
745 | \ :setlocal fileformat=unix
746 | \ :write! ++encoding=utf-8
747 | \ :edit!
748 |
749 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
750 |
751 | " [,h ] Show hex dump.
752 |
753 | nmap h :%!xxd
754 |
755 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
756 |
757 | " [,l ] Toggle `set list`.
758 |
759 | nmap l :set list!
760 |
761 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
762 |
763 | " [,n ] Toggle `set relativenumber`.
764 |
765 | nmap n :call ToggleRelativeLineNumbers()
766 |
767 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
768 |
769 | " [,pp ] Pretty print
770 |
771 | map pp :call PrettyPrint()
772 |
773 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
774 |
775 | " [,rl ] Toggle `RainbowLevels`.
776 |
777 | map rl :RainbowLevelsToggle
778 |
779 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
780 |
781 | " [,sb ] Strip BOM (Byte Order Mark).
782 |
783 | nmap sb :call StripBOM()
784 |
785 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
786 |
787 | " [,sw ] Strip trailing whitespace.
788 |
789 | nmap sw :call StripTrailingWhitespaces()
790 |
791 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
792 |
793 | " [,t ] Toggle NERDTree.
794 |
795 | map t :NERDTreeToggle
796 |
797 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
798 |
799 | " [,ti ] Toggle indent.
800 |
801 | nmap ti IndentGuidesToggle
802 |
803 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
804 |
805 | " [,tl ] Toggle show limits.
806 |
807 | nmap tl :call ToggleLimits()
808 |
809 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
810 |
811 | " [,ts ] Toggle Syntastic.
812 |
813 | nmap ts :SyntasticToggleMode \| w
814 |
815 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
816 |
817 | " [,v ] Make the opening of the `.vimrc` file easier.
818 |
819 | nmap v :vsp $MYVIMRC
820 |
821 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
822 |
823 | " [,W ] Sudo write.
824 |
825 | map W :w !sudo tee %
826 |
827 |
828 | " ----------------------------------------------------------------------
829 | " | Status Line |
830 | " ----------------------------------------------------------------------
831 |
832 | " Terminal types:
833 | "
834 | " 1) term (normal terminals, e.g.: vt100, xterm)
835 | " 2) cterm (color terminals, e.g.: MS-DOS console, color-xterm)
836 | " 3) gui (GUIs)
837 |
838 | highlight ColorColumn
839 | \ term=NONE
840 | \ cterm=NONE ctermbg=237 ctermfg=NONE
841 | \ gui=NONE guibg=#073642 guifg=NONE
842 |
843 | highlight CursorLine
844 | \ term=NONE
845 | \ cterm=NONE ctermbg=235 ctermfg=NONE
846 | \ gui=NONE guibg=#073642 guifg=NONE
847 |
848 | highlight CursorLineNr
849 | \ term=bold
850 | \ cterm=bold ctermbg=NONE ctermfg=178
851 | \ gui=bold guibg=#073642 guifg=Orange
852 |
853 | highlight LineNr
854 | \ term=NONE
855 | \ cterm=NONE ctermfg=241 ctermbg=NONE
856 | \ gui=NONE guifg=#839497 guibg=#073642
857 |
858 | highlight User1
859 | \ term=NONE
860 | \ cterm=NONE ctermbg=237 ctermfg=Grey
861 | \ gui=NONE guibg=#073642 guifg=#839496
862 |
863 | " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
864 |
865 | set statusline=
866 | set statusline+=%1* " User1 highlight
867 | set statusline+=\ [%n] " Buffer number
868 | set statusline+=\ %{GetGitBranchName()} " Git branch name
869 | set statusline+=\ [%f] " File path
870 | set statusline+=%m " Modified flag
871 | set statusline+=%r " Readonly flag
872 | set statusline+=%h " Help file flag
873 | set statusline+=%w " Preview window flag
874 | set statusline+=%y " File type
875 | set statusline+=[
876 | set statusline+=%{&ff} " File format
877 | set statusline+=:
878 | set statusline+=%{strlen(&fenc)?&fenc:'none'} " File encoding
879 | set statusline+=]
880 | set statusline+=%= " Left/Right separator
881 | set statusline+=%c " File encoding
882 | set statusline+=,
883 | set statusline+=%l " Current line number
884 | set statusline+=/
885 | set statusline+=%L " Total number of lines
886 | set statusline+=\ (%P)\ " Percent through file
887 |
888 | " Example result:
889 | "
890 | " [1] [main] [vim/vimrc][vim][unix:utf-8] 17,238/381 (59%)
891 |
892 |
893 | " ----------------------------------------------------------------------
894 | " | Local Settings |
895 | " ----------------------------------------------------------------------
896 |
897 | " Load local settings if they exist.
898 | "
899 | " [!] The following needs to remain at the end of this file in
900 | " order to allow any of the above settings to be overwritten
901 | " by the local ones.
902 |
903 | if filereadable(glob("~/.vimrc.local"))
904 | source ~/.vimrc.local
905 | endif
906 |
--------------------------------------------------------------------------------