-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakesymlinks.sh
More file actions
executable file
·49 lines (40 loc) · 1.31 KB
/
makesymlinks.sh
File metadata and controls
executable file
·49 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
############################
# .make.sh
# This script creates symlinks from the home directory to any desired dotfiles in ~/dotfiles
############################
########## Variables
dir="$HOME/dotfiles" # dotfiles directory
olddir="$HOME/dotfiles_old" # old dotfiles backup directory
files="bash_aliases bash_profile bash_logout bashrc inputrc emacs tmux.conf dircolors gitconfig" # list of files/folders to symlink in homedir
if [[ $1 == 'xserver' ]] ; then
files="$files Xresources"
fi
# create dotfiles_old in homedir
if [[ ! -d "$olddir" ]] ; then
echo "Creating $olddir for backup of any existing dotfiles in ~"
mkdir -p "$olddir"
echo "...done"
fi
# change to the dotfiles directory
echo "Changing to the $dir directory"
cd "$dir" || exit
echo "...done"
# move any existing dotfiles in homedir to dotfiles_old directory, then create symlinks
for file in $files; do
src="$dir/$file"
dst="$HOME/.$file"
if [[ ! -e "$src" ]]; then
echo "Skipping $file: source file not found."
continue
fi
if [[ -e "$dst" || -L "$dst" ]]; then
backup="$olddir/${file}_$(date +%Y%m%d%H%M%S)"
echo "Backing up $dst to $backup"
mv "$dst" "$backup"
fi
echo "Creating symlink $dst -> $src"
ln -snf "$src" "$dst"
done
mkdir -p "$HOME/bin"
ln -snf "$dir/freemem.sh" "$HOME/bin/freemem.sh"