vsc-dotfiles/install.sh

111 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
function install_pkg() {
if hash apt-get 2>/dev/null; then
sudo -n apt-get update
sudo -n DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ${$}
return
fi
if hash nix 2>/dev/null; then
echo "INSTALL ${@} yourself with nix"
return
fi
}
function setup_ssh() {
configfile=~/.ssh/config
if grep -Fxq "# dotfiles installed" ${configfile}; then
return
fi
mkdir -p ~/.ssh
touch ${configfile}
chmod 644 ${configfile}
cat << EOF >> ${configfile}
Include ${HOME}/dotfiles/ssh.config
# dotfiles installed
EOF
}
function setup_git() {
configfile=~/.gitconfig
if grep -Fxq "# dotfiles installed" ${configfile}; then
return
fi
cat << EOF > ${configfile}
[include]
path = ${HOME}/dotfiles/git/gitconfig
[core]
excludesfile = ${HOME}/dotfiles/git/gitignore_global
# dotfiles installed
EOF
setup_ssh
}
function setup_tmux() {
configfile=~/.tmux.conf
if grep -Fxq "# dotfiles installed" ${configfile}; then
return
fi
install_pkg tmux
cat << EOF > ${configfile}
source ${HOME}/dotfiles/tmux/tmux.conf
# dotfiles.installed
EOF
}
function setup_fish() {
install_pkg fish
USER=`whoami`
sudo -n chsh $USER -s $(which fish)
# Force fish shell for devcontainers
echo "exec $(which fish) -l" >> ~/.bashrc
echo "exec $(which fish) -l" >> ~/.zshrc
mkdir -p ~/.config/
ln -s ~/dotfiles/fish ~/.config/fish
}
function setup_nvim() {
install_pkg neovim
mkdir -p ~/.config/nvim/
ln -s ~/dotfiles/init.vim ~/.config/nvim/init.vim
# Install NERDtree plugin
git clone --single-branch https://github.com/preservim/nerdtree.git ~/.config/nvim/pack/vendor/start/nerdtree
git clone --single-branch https://tpope.io/vim/commentary.git ~/.config/nvim/pack/vendor/start/commentary
nvim -u NONE -c "helptags ~/.config/nvim/pack/vendor/start/nerdtree/doc" -c q
nvim -u NONE -c "helptags ~/.config/nvim/pack/vendor/start/commentary/doc" -c q
}
function main() {
install_pkg locales less
#echo "sv_SE.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen
#sudo locale-gen
setup_fish
setup_ssh
setup_git
if [[ ${REMOTE_CONTAINERS} || ${DEVCONTAINER} ]]; then
echo "INSTALLING IN DEVCONTAINER"
echo "set -x EDITOR code" >> ~/.config/fish/local.fish
else
setup_tmux
setup_nvim
fi
}
main $@