Last active
February 22, 2022 17:05
-
-
Save ViBiOh/e38aeb07d6d56dfa78256b61781478c5 to your computer and use it in GitHub Desktop.
Dotfiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o nounset -o pipefail -o errexit | |
main() { | |
local INSTALL_PATH="${HOME}/code" | |
local GITHUB_USER="ViBiOh" | |
local DOTFILES_NAME="dotfiles" | |
local DOTFILES_BRANCH="main" | |
local ARCHIVE_FILENAME="${INSTALL_PATH}/dotfiles.zip" | |
mkdir -p "${INSTALL_PATH}" | |
curl --disable --silent --show-error --location --max-time 60 --output "${ARCHIVE_FILENAME}" "https://github.com/${GITHUB_USER}/${DOTFILES_NAME}/archive/${DOTFILES_BRANCH}.zip" | |
unzip "${ARCHIVE_FILENAME}" -d "${INSTALL_PATH}" | |
rm -f "${ARCHIVE_FILENAME}" | |
rm -rf "${INSTALL_PATH:?}/${DOTFILES_NAME}" | |
mv "${INSTALL_PATH}/${DOTFILES_NAME}-${DOTFILES_BRANCH}" "${INSTALL_PATH}/${DOTFILES_NAME}" | |
( | |
cd "${INSTALL_PATH}/${DOTFILES_NAME}" | |
"./init" -a | |
git init | |
git remote add origin "http://github.com/${GITHUB_USER}/${DOTFILES_NAME}.git" | |
git fetch origin | |
git checkout --force "${DOTFILES_BRANCH}" | |
) | |
} | |
main "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o nounset -o pipefail -o errexit | |
readonly CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
create_symlinks() { | |
while IFS= read -r -d '' file; do | |
local BASENAME_FILE | |
BASENAME_FILE="$(basename "${file}")" | |
if [[ -n ${FILE_LIMIT} ]] && [[ ${BASENAME_FILE} != "${FILE_LIMIT}" ]]; then | |
continue | |
fi | |
[[ -r ${file} ]] && [[ -e ${file} ]] && rm -f "${HOME}/.${BASENAME_FILE}" && ln -s "${file}" "${HOME}/.${BASENAME_FILE}" | |
done < <(find "${CURRENT_DIR}/symlinks" -type f -print0) | |
} | |
browse_install() { | |
while IFS= read -r -d '' file; do | |
local BASENAME_FILE | |
BASENAME_FILE="$(basename "${file}")" | |
local UPPERCASE_FILENAME | |
UPPERCASE_FILENAME="$(printf "%s" "${BASENAME_FILE}" | tr "[:lower:]" "[:upper:]")" | |
local DISABLE_VARIABLE_NAME="DOTFILES_NO_${UPPERCASE_FILENAME}" | |
if [[ ${!DISABLE_VARIABLE_NAME:-} == "true" ]]; then | |
continue | |
fi | |
if [[ -r ${file} ]]; then | |
for action in "${@}"; do | |
unset -f "${action}" | |
done | |
source "${file}" | |
for action in "${@}"; do | |
if [[ $(type -t "${action}") == "function" ]]; then | |
print_title "${action} - ${BASENAME_FILE}" | |
"${action}" | |
fi | |
done | |
fi | |
done < <(find "${CURRENT_DIR}/install" -type f -print0 | LC_ALL=C sort --zero-terminated) | |
} | |
browse_install clean install | |
browse_install credentials | |
create_symlinks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o nounset -o pipefail -o errexit | |
clean() { | |
rm -rf "${HOME}/.cache" | |
sudo rm -rf "${HOME}/opt" | |
} | |
install() { | |
mkdir -p "${HOME}/opt/bin" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o nounset -o pipefail -o errexit | |
install() { | |
local PACKAGES=("bash" "bash-completion" "make" "htop" "openssl" "curl" "ncdu" "jq") | |
if [[ ${OSTYPE} =~ ^darwin ]]; then | |
cat >"${HOME}/.bash_profile" <<END_OF_BASH_PROFILE | |
#!/usr/bin/env bash | |
if [[ -f "${HOME}/.bashrc" ]]; then | |
source "${HOME}/.bashrc" | |
fi | |
END_OF_BASH_PROFILE | |
local SCRIPT_DIR | |
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
if ! command -v brew >/dev/null 2>&1; then | |
/bin/bash -c "$(curl --disable --silent --show-error --location https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" | |
source "${SCRIPT_DIR}/../sources/_homebrew" | |
fi | |
packages_update | |
packages_install "${PACKAGES[@]}" fswatch jdupes | |
if [[ $(grep --count "$(brew --prefix)" "/etc/shells") -eq 0 ]]; then | |
printf "+-------------------------+\n" | |
printf "| changing shell for user |\n" | |
printf "+-------------------------+\n" | |
printf "%s/bin/bash\n" "$(brew --prefix)" | sudo tee -a "/etc/shells" >/dev/null | |
chsh -s "$(brew --prefix)/bin/bash" -u "$(whoami)" | |
fi | |
elif command -v apt-get >/dev/null 2>&1; then | |
packages_update | |
packages_install "apt-transport-https" | |
packages_install "${PACKAGES[@]}" dnsutils jdupes | |
elif command -v pacman >/dev/null 2>&1; then | |
packages_update | |
packages_install "${PACKAGES[@]}" inetutils | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ -d "${HOME}/opt/bin" ]]; then | |
export PATH="${HOME}/opt/bin:${PATH}" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
[[ -z ${PS1:-} ]] && return | |
set_locale() { | |
local LOCALES=("en_US.UTF-8" "en_US.utf8" "C.UTF-8" "C") | |
local ALL_LOCALES | |
ALL_LOCALES="$(locale -a)" | |
for locale in "${LOCALES[@]}"; do | |
if [[ $(echo "${ALL_LOCALES}" | grep --count "${locale}") -eq 1 ]]; then | |
export LC_ALL="${locale}" | |
export LANG="${locale}" | |
export LANGUAGE="${locale}" | |
return | |
fi | |
done | |
return 1 | |
} | |
script_dir() { | |
if [[ -L ${BASH_SOURCE[0]} ]]; then | |
dirname "$(readlink "${BASH_SOURCE[0]}")" | |
else | |
( | |
cd "$(dirname "${BASH_SOURCE[0]}")" && pwd | |
) | |
fi | |
} | |
source_all() { | |
local SCRIPT_DIR | |
SCRIPT_DIR="$(script_dir)" | |
for file in "${SCRIPT_DIR}/../sources/"*; do | |
[[ -r ${file} ]] && [[ -f ${file} ]] && source "${file}" | |
done | |
} | |
set_locale | |
source_all | |
if [[ -e "${HOME}/.localrc" ]]; then | |
source "${HOME}/.localrc" | |
fi | |
unset -f set_locale | |
unset -f source_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment