diff options
-rw-r--r-- | home.txt | 17 | ||||
-rwxr-xr-x | home.zsh | 42 | ||||
-rwxr-xr-x | import.zsh | 25 | ||||
-rwxr-xr-x | link.zsh | 38 | ||||
-rwxr-xr-x | prune.zsh | 9 |
5 files changed, 59 insertions, 72 deletions
diff --git a/home.txt b/home.txt new file mode 100644 index 00000000..4489872e --- /dev/null +++ b/home.txt @@ -0,0 +1,17 @@ +.bin/sup +.bin/tup +.bin/up +.config/git/config +.config/git/ignore +.config/htop/htoprc +.config/nvim/colors/trivial.vim +.config/nvim/init.vim +.config/nvim/syntax/nasm.vim +.gdbinit +.gnupg/gpg-agent.conf +.hushlogin +.inputrc +.lldbinit +.psqlrc +.ssh/config +.zshrc diff --git a/home.zsh b/home.zsh new file mode 100755 index 00000000..8490a3b5 --- /dev/null +++ b/home.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +set -o errexit -o nounset -o pipefail + +fail() { + echo "$@" + exit 1 +} + +link() { + local relPath srcPath dstPath + < home.txt while read relPath; do + srcPath="$PWD/home/$relPath" + dstPath="$HOME/$relPath" + [ -L "$dstPath" ] && continue + mkdir -p "$(dirname "$dstPath")" + ln -s "$srcPath" "$dstPath" + echo "$relPath" + done +} + +import() { + local relPath srcPath dstPath + relPath="$1" + srcPath="$HOME/$relPath" + dstPath="$PWD/home/$relPath" + [ -f "$dstPath" ] && fail "$dstPath exists" + mkdir -p "$(dirname "$dstPath")" + mv "$srcPath" "$dstPath" + ln -s "$dstPath" "$srcPath" + echo "$relPath" >> home.txt + sort -o home.txt home.txt +} + +prune() { + local linkPath + find -L ~ -type l -lname "$PWD/*" | while read linkPath; do + rm "$linkPath" + echo "$linkPath" + done +} + +$@ diff --git a/import.zsh b/import.zsh deleted file mode 100755 index 8c3309b0..00000000 --- a/import.zsh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env zsh -set -o errexit -o nounset -o pipefail - -# Import file from ~ and replace it with a symlink. - -fail() { - echo "$1" - exit 1 -} - -[ -z "$1" ] && fail 'no path' - -source_path="$HOME/$1" -dest_path="$PWD/home/$1" - -[ -f "$dest_path" ] && fail "$dest_path exists" - -mkdir -p "$(dirname "$dest_path")" -mv "$source_path" "$dest_path" -ln -s "$dest_path" "$source_path" - -echo "link '$1'" >> link.zsh -head=$(head -n 21 link.zsh) -tail=$(tail -n +21 link.zsh | sort) -echo "$head\n$tail" > link.zsh diff --git a/link.zsh b/link.zsh deleted file mode 100755 index b9e08bc7..00000000 --- a/link.zsh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env zsh -set -o errexit -o nounset -o pipefail - -# Create symbolic links in ~. - -fail() { - echo "$1" - exit 1 -} - -link() { - local source_path="$PWD/home/$1" - local dest_path="$HOME/$1" - - [ -L "$dest_path" ] && return - - mkdir -p "$(dirname "$dest_path")" - ln -s "$source_path" "$dest_path" - echo "$1" -} - -link '.bin/sup' -link '.bin/tup' -link '.bin/up' -link '.config/git/config' -link '.config/git/ignore' -link '.config/htop/htoprc' -link '.config/nvim/colors/trivial.vim' -link '.config/nvim/init.vim' -link '.config/nvim/syntax/nasm.vim' -link '.gdbinit' -link '.gnupg/gpg-agent.conf' -link '.hushlogin' -link '.inputrc' -link '.lldbinit' -link '.psqlrc' -link '.ssh/config' -link '.zshrc' diff --git a/prune.zsh b/prune.zsh deleted file mode 100755 index 26dd27cc..00000000 --- a/prune.zsh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env zsh -set -o errexit -o nounset -o pipefail - -# Remove broken symbolic links in ~. - -find -L ~ -type l -lname "$PWD/*" | while read link; do - rm "$link" - echo "$link" -done |