diff --git a/TODO.org b/TODO.org index 4a00cb8..72720d8 100644 --- a/TODO.org +++ b/TODO.org @@ -1,5 +1,4 @@ -* Dotfiles -** Change deploy script to python * DOOM Emacs Jump to favorite files Figure out emacs-based terminals +Figure out anaconda mode virtualenvs diff --git a/deploy.py b/deploy.py new file mode 100644 index 0000000..95fa575 --- /dev/null +++ b/deploy.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import sys +from pathlib import Path + +home = Path.home().resolve().absolute() +dotdir = Path(__file__).parent.resolve().absolute() + +simple = [ + # 'gemrc', + 'gitconfig', + 'ideavimrc', + 'lein', + # 'irbrc', + # 'nethackrc', + # 'spacemacs', + 'tmux.conf', + 'vimrc' +] + +targeted = { + 'doom': '.doom.d', + 'fish': '.config/fish', +} + + +def deploy(source_name, target_name, dry_run=False): + source = dotdir.joinpath(source_name) + target = home.joinpath(target_name) + + if not source.exists(): + raise FileNotFoundError(f"Asked to link {source_name}, which doesn't exist in {dotdir}.") + + if target.exists(): + if target.samefile(source): + print(f"{target}->{source} already linked.") + return + + backup_path = target.parent.joinpath(f"{target.name}.bak") + + print(f"{target} moves to {backup_path}") + if not dry_run: + target.replace(backup_path) + + if not target.parent.exists(): + print(f"making parent directories of {target}") + if not dry_run: + target.parent.mkdir(parents=True) + + print(f"linking {target} to {source}") + if not dry_run: + target.symlink_to(source) + + +def main(dry_run=True): + for source in simple: + target = f".{source}" + deploy(source, target, dry_run=dry_run) + + for source, target in targeted.items(): + deploy(source, target, dry_run=dry_run) + + +if __name__ == '__main__': + try: + main(False) + except FileNotFoundError as e: + print(e) + sys.exit(1) diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index 64fdc8e..0000000 --- a/deploy.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -echo "Deploying dotfiles..." - -pushd $HOME &> /dev/null - -FILES=($(ls -p .dotfiles | egrep -v "/\$|\\.sh|TODO")) - -for file in ${FILES[@]}; do - mv .$file .${file}.bak - ln -s .dotfiles/$file .$file -done - -mkdir -p .config -mv .config/fish .config/fish.bak -ln -s $HOME/.dotfiles/fish .config/fish - -mv .lein .lein.bak -ln -s $HOME/.dotfiles/lein .lein - -mv .doom.d .doom.d.bak -ln -s $HOME/.dotfiles/doom .doom.d - -popd &> /dev/null - -echo "...done." diff --git a/setup_linux.sh b/setup_linux.sh index de2c5ed..f3a041a 100644 --- a/setup_linux.sh +++ b/setup_linux.sh @@ -63,21 +63,17 @@ gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:nocaps']" # Use local time so as to not conflict with Windows timedatectl set-local-rtc 1 --adjust-system-clock +# Change default shell +sudo chsh -ls /usr/bin/fish $USER + # SSH setup ssh-keygen -t rsa -f $HOME/.ssh/id_rsa -q -P "" -echo "Please add this key to GitHub, then press ENTER to continue." +echo "Your SSH public key is:" echo "" -cat $HOME/.ssh/id_rsa.pub +cat ~/.ssh/id_rsa.pub echo "" -read +read -p "Please add it to GitHub, then press enter to continue." -git clone git@github.com:tim-mccarthy/dotfiles.git .dotfiles -pushd .dotfiles -./deploy.sh -popd - -sudo chsh -ls /usr/bin/fish $USER - -git clone https://github.com/hlissner/doom-emacs ~/.emacs.d -~/.emacs.d/bin/doom install +git clone git@github.com:tim-mccarthy/dotfiles.git $HOME/.dotfiles +bash ~/.dotfiles/setup_unix_common.sh diff --git a/setup_mac.sh b/setup_mac.sh index 76e0183..4e09f2d 100644 --- a/setup_mac.sh +++ b/setup_mac.sh @@ -5,12 +5,12 @@ brew update brew install fish git brew cask install emacs -git clone https://github.com/syl20bnr/spacemacs .emacs.d +curl -s 'https://macapps.link/en/firefox-bettertouchtool-dropbox-alfred-sublime-iterm-unarchiver-transmit' | sh sudo bash -c "echo /usr/local/bin/fish >> /etc/shells" chsh -s /usr/local/bin/fish -cat /dev/zero | ssh-keygen -q -N "" +ssh-keygen -t rsa -f $HOME/.ssh/id_rsa -q -P "" echo "Your SSH public key is:" echo "" @@ -18,5 +18,5 @@ cat ~/.ssh/id_rsa.pub echo "" read -p "Please add it to GitHub, then press enter to continue." -curl -s 'https://macapps.link/en/chrome-bettertouchtool-dropbox-alfred-sublime-iterm-unarchiver-transmit' | sh - +git clone git@github.com:tim-mccarthy/dotfiles.git $HOME/.dotfiles +bash ~/.dotfiles/setup_unix_common.sh diff --git a/setup_unix_common.sh b/setup_unix_common.sh new file mode 100644 index 0000000..2383979 --- /dev/null +++ b/setup_unix_common.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +python3 $HOME/.dotfiles/deploy.py + +git clone https://github.com/hlissner/doom-emacs ~/.emacs.d +~/.emacs.d/bin/doom install +~/.emacs.d/bin/doom sync