diff options
-rwxr-xr-x | import.sh | 23 | ||||
-rwxr-xr-x | import.zsh | 21 | ||||
-rwxr-xr-x | install.sh | 28 | ||||
-rwxr-xr-x | link.zsh (renamed from link.sh) | 24 | ||||
-rwxr-xr-x | prune.zsh (renamed from prune.sh) | 9 |
5 files changed, 50 insertions, 55 deletions
diff --git a/import.sh b/import.sh deleted file mode 100755 index d7c3b072..00000000 --- a/import.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env zsh - -# Import a file from ~ and replace it with a symlink. - -set -o errexit -o nounset -o pipefail - -error() { - echo "$1" - exit 1 -} - -[ -z "$1" ] && error 'no path' - -source_path="$HOME/$1" -dest_path="$PWD/home/$1" - -[ -f "$dest_path" ] && error "$dest_path already exists" -[ -f "$source_path" ] || error "$source_path does not exist" - -mkdir -p "$(dirname "$dest_path")" -mv "$source_path" "$dest_path" -ln -s "$dest_path" "$source_path" -echo "link '$1'" >> link.sh diff --git a/import.zsh b/import.zsh new file mode 100755 index 00000000..6b69865a --- /dev/null +++ b/import.zsh @@ -0,0 +1,21 @@ +#!/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 diff --git a/install.sh b/install.sh index 0684b053..2e159f5a 100755 --- a/install.sh +++ b/install.sh @@ -3,26 +3,26 @@ set -eu common='gdb git gnupg htop sl the_silver_searcher tree' +homebrew=https://raw.githubusercontent.com/Homebrew/install/master/install macos() { - homebrew=https://raw.githubusercontent.com/Homebrew/install/master/install - xcode-select --install || true - [ ! -f /usr/local/bin/brew ] && ruby -e "`curl -fsSL $homebrew`" - brew install $common - brew install ddate neovim/neovim/neovim openssh + xcode-select --install || true + [ ! -f /usr/local/bin/brew ] && ruby -e "`curl -fsSL $homebrew`" + brew install $common + brew install ddate neovim/neovim/neovim openssh } freebsd() { - pkg install $common - pkg install curl ddate neovim sudo zsh + pkg install $common + pkg install curl ddate neovim sudo zsh } arch() { - pacman -Sy - pacman -S --needed base-devel - pacman -S --needed $common - pacman -S --needed neovim openssh zsh + pacman -Sy + pacman -S --needed base-devel + pacman -S --needed $common + pacman -S --needed neovim openssh zsh } -[ "$(uname)" = 'Darwin' ] && macos && exit -[ -f /usr/local/sbin/pkg ] && freebsd && exit -[ -f /usr/bin/pacman ] && arch && exit +[ "$(uname)" = 'Darwin' ] && macos +[ -f /usr/local/sbin/pkg ] && freebsd +[ -f /usr/bin/pacman ] && arch diff --git a/link.sh b/link.zsh index 4afde60c..13bb175b 100755 --- a/link.sh +++ b/link.zsh @@ -1,24 +1,22 @@ #!/usr/bin/env zsh - -# Create symlines in ~ for files in home. - set -o errexit -o nounset -o pipefail -error() { - echo "$1" - exit 1 +# Create symbolic links in ~. + +fail() { + echo "$1" + exit 1 } link() { - local source_path="$PWD/home/$1" - local dest_path="$HOME/$1" + local source_path="$PWD/home/$1" + local dest_path="$HOME/$1" - [ -h "$dest_path" ] && return - [ -e "$dest_path" ] && error "$dest_path exists" + [ -L "$dest_path" ] && return - mkdir -p "$(dirname "$dest_path")" - ln -s "$source_path" "$dest_path" - echo "$1" + mkdir -p "$(dirname "$dest_path")" + ln -s "$source_path" "$dest_path" + echo "$1" } link '.bin/sup' diff --git a/prune.sh b/prune.zsh index 09ed8d35..26dd27cc 100755 --- a/prune.sh +++ b/prune.zsh @@ -1,10 +1,9 @@ #!/usr/bin/env zsh - -# Remove symbolic links in ~ to files that no longer exist. - 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" + rm "$link" + echo "$link" done |