Skip to content

Instantly share code, notes, and snippets.

@oconnor663
Created August 16, 2015 05:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oconnor663/5aaaf941a9c1606450fa to your computer and use it in GitHub Desktop.
Save oconnor663/5aaaf941a9c1606450fa to your computer and use it in GitHub Desktop.
dotfiles install script comparison
#! /usr/bin/env python3
import os
from pathlib import Path
from shutil import which
from subprocess import run
import sys
here = Path(__file__).parent.resolve()
os.chdir(str(here))
if here != Path.home()/"dotfiles":
print("can only be installed from ~/dotfiles")
sys.exit(1)
run("peru sync", shell=True, check=True)
newshell = "/bin/zsh"
oldshell = os.environ.get("SHELL")
if oldshell != newshell:
print("Switching default shell from {} to {}..."
.format(oldshell, newshell))
run("chsh -s " + newshell)
def link(src, dest):
dest = Path(dest).expanduser()
dest.parent.mkdir(exist_ok=True, parents=True)
if dest.exists():
dest.unlink()
os.symlink(str(here/src), str(dest))
link("ackrc", "~/.ackrc")
link("gitconfig", "~/.gitconfig")
link("hgrc", "~/.hgrc")
link("tmux.conf", "~/.tmux.conf")
link("tmux.desktop", "~/.local/share/applications/tmux.desktop")
link("vim", "~/.vim")
link("vimrc", "~/.vimrc")
link("zshrc", "~/.zshrc")
# Doing this in .vimrc is unnecessarily hard.
Path("~/.vim-tmp").expanduser().mkdir(exist_ok=True)
for script in Path("bin").iterdir():
link(script, "~"/script)
# For Gnome, set terminal preferences and remap caps lock.
if which("dconf"):
run("dconf load / < {}".format(here/"gnome-dconf-settings"),
shell=True, check=True)
#!/bin/bash
set -e
HERE=$(cd $(dirname "$BASH_SOURCE"); pwd)
if [[ "$HERE" != "$HOME/dotfiles" ]] ; then
echo 'can only be installed from ~/dotfiles'
exit 1
fi
cd "$HERE"
peru sync
newshell=/bin/zsh
if [ $SHELL != $newshell ]; then
echo Switching default shell from $SHELL to $newshell...
chsh -s $newshell
fi
function link {
local src="$1"
local dest="$2"
mkdir -p $(dirname "$dest")
ln -sfn "$HERE/$src" "$dest"
}
link ackrc ~/.ackrc
link gitconfig ~/.gitconfig
link hgrc ~/.hgrc
link tmux.conf ~/.tmux.conf
link tmux.desktop ~/.local/share/applications/tmux.desktop
link vim ~/.vim
link vimrc ~/.vimrc
link zshrc ~/.zshrc
# Doing this in .vimrc is unnecessarily hard.
mkdir -p ~/.vim-tmp
for script in $(ls bin); do
link "bin/$script" ~/bin/"$script"
done
# For Gnome, set terminal preferences and remap caps lock.
if which dconf &> /dev/null ; then
dconf load / < $HERE/gnome-dconf-settings
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment