mirror of https://github.com/nirenjan/dotfiles.git
				
				
				
			Update install script lnfile functionality
This allows me to specify the destination folder if the link name doesn't need to be changed, i.e., if I want to install vim/ftplugin/ruby.vim, I no longer need to specify the following line: lnfile vim/ftplugin/ruby.vim ~/.vim/ftplugin/ruby Instead, I can simply give the destination folder, just terminate it with a slash character as follows: lnfile vim/ftplugin/ruby.vim ~/.vim/ftplugin/vimbundler
							parent
							
								
									1507f357e4
								
							
						
					
					
						commit
						77cc345af4
					
				
							
								
								
									
										64
									
								
								install
								
								
								
								
							
							
						
						
									
										64
									
								
								install
								
								
								
								
							|  | @ -25,23 +25,32 @@ mkfolder() | ||||||
| # Symlink file to destination folder | # Symlink file to destination folder | ||||||
| lnfile() | lnfile() | ||||||
| { | { | ||||||
|     FILE_PATH=$(dirname $2) |     # See if we are linking to a directory | ||||||
|     FILE_NAME=$(basename $2) |     if [[ $2 =~ /$ ]] | ||||||
|     DEST_FILE="$DF_PATH/$1" |     then | ||||||
|  |         FILE_PATH=$2 | ||||||
|  |         FILE_NAME=$(basename $1) | ||||||
|  |         DST_FILE="${FILE_PATH}${FILE_NAME}" | ||||||
|  |     else | ||||||
|  |         FILE_PATH=$(dirname $2) | ||||||
|  |         FILE_NAME=$(basename $2) | ||||||
|  |         DST_FILE="$FILE_PATH/$FILE_NAME" | ||||||
|  |     fi | ||||||
|  |     SRC_FILE="$DF_PATH/$1" | ||||||
|     WRITE_LINK=0 |     WRITE_LINK=0 | ||||||
| 
 | 
 | ||||||
|     # See if the target exists |     # See if the target exists | ||||||
|     if [[ -e $2 ]] |     if [[ -e $DST_FILE ]] | ||||||
|     then |     then | ||||||
|         # Is the target a symbolic link? |         # Is the target a symbolic link? | ||||||
|         if [[ -L $2 ]] |         if [[ -L $DST_FILE ]] | ||||||
|         then |         then | ||||||
|             POINTS_TO=$(readlink $2) |             POINTS_TO=$(readlink $DST_FILE) | ||||||
|             # Does it point to our file? |             # Does it point to our file? | ||||||
|             if [[ "$POINTS_TO" != "$DEST_FILE" ]] |             if [[ "$POINTS_TO" != "$SRC_FILE" ]] | ||||||
|             then |             then | ||||||
|                 echo "Target $2 points to a different file - $POINTS_TO" |                 echo "Target $DST_FILE points to a different file - $POINTS_TO" | ||||||
|                 echo -n "Replace link to point to $DEST_FILE? [y/n] " |                 echo -n "Replace link to point to $SRC_FILE? [y/n] " | ||||||
|                 read -n1 |                 read -n1 | ||||||
|                 echo |                 echo | ||||||
| 
 | 
 | ||||||
|  | @ -49,28 +58,33 @@ lnfile() | ||||||
|                 then |                 then | ||||||
|                     WRITE_LINK=1 |                     WRITE_LINK=1 | ||||||
|                     # Remove the old symbolic link |                     # Remove the old symbolic link | ||||||
|                     rm -f $2 |                     rm -f $DST_FILE | ||||||
|                 fi |                 fi | ||||||
|             #else |             #else | ||||||
|                 # It already points to our file. No point in rewriting it. |                 # It already points to our file. No point in rewriting it. | ||||||
|             fi |             fi | ||||||
|         else |         else | ||||||
|             # No, it's not a symbolic link |             # No, it's not a symbolic link | ||||||
|             echo "Target $2 is not a symbolic link!" |             echo "Target $DST_FILE is not a symbolic link!" | ||||||
|             echo "Backing up to $2.bak" |             echo "Backing up to $DST_FILE.bak" | ||||||
|             mv -v $2 ${2}.bak |             mv -v $DST_FILE ${DST_FILE}.bak | ||||||
|             WRITE_LINK=1 |             WRITE_LINK=1 | ||||||
|         fi |         fi | ||||||
|     else |     else | ||||||
|         WRITE_LINK=1 |         WRITE_LINK=1 | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
|  |     if [[ ! -z $DEBUG ]] | ||||||
|  |     then | ||||||
|  |         echo -n "Linking " | ||||||
|  |         [[ ! -z $WRITE_LINK ]] && echo -n "(NOT) " | ||||||
|  |         echo "'$DST_FILE' -> '$SRC_FILE'" | ||||||
|  |     fi | ||||||
|  | 
 | ||||||
|     if [[ $WRITE_LINK == 1 ]] |     if [[ $WRITE_LINK == 1 ]] | ||||||
|     then |     then | ||||||
|         echo "Installing $1" |         echo "Installing $1" | ||||||
|         pushd $FILE_PATH >/dev/null |         ln -s "$SRC_FILE" "$DST_FILE" | ||||||
|         ln -s "$DF_PATH/$1" $FILE_NAME |  | ||||||
|         popd >/dev/null |  | ||||||
|     fi |     fi | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -118,15 +132,15 @@ echo Installing dotfiles from $PRINT_PATH | ||||||
| mkfolder ~/bin | mkfolder ~/bin | ||||||
| 
 | 
 | ||||||
| # Install scripts | # Install scripts | ||||||
| lnfile scripts/beep ~/bin/beep | lnfile scripts/beep ~/bin/ | ||||||
| lnfile scripts/sdate ~/bin/stardate | lnfile scripts/sdate ~/bin/stardate | ||||||
| lnfile scripts/settitle ~/bin/settitle | lnfile scripts/settitle ~/bin/ | ||||||
| lnfile scripts/smartwd ~/bin/smartwd | lnfile scripts/smartwd ~/bin/ | ||||||
| 
 | 
 | ||||||
| # Don't bother installing the note script on a Mac, it doesn't work that well | # Don't bother installing the note script on a Mac, it doesn't work that well | ||||||
| if [[ "$(uname)" != *"Darwin"* ]] | if [[ "$(uname)" != *"Darwin"* ]] | ||||||
| then | then | ||||||
|     lnfile scripts/note ~/bin/note |     lnfile scripts/note ~/bin/ | ||||||
|     lnfile scripts/note ~/bin/n |     lnfile scripts/note ~/bin/n | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
|  | @ -170,13 +184,13 @@ mkfolder ~/.vim/syntax | ||||||
| lnfile vimrc ~/.vimrc | lnfile vimrc ~/.vimrc | ||||||
| 
 | 
 | ||||||
| # Install my plugins | # Install my plugins | ||||||
| lnfile vim/plugin/long-lines.vim ~/.vim/plugin/long-lines.vim | lnfile vim/plugin/long-lines.vim        ~/.vim/plugin/ | ||||||
| lnfile vim/plugin/match-brackets.vim ~/.vim/plugin/match-brackets.vim | lnfile vim/plugin/match-brackets.vim    ~/.vim/plugin/ | ||||||
| 
 | 
 | ||||||
| # Install my filetype plugins | # Install my filetype plugins | ||||||
| lnfile vim/ftplugin/make.vim ~/.vim/ftplugin/make.vim | lnfile vim/ftplugin/make.vim            ~/.vim/ftplugin/ | ||||||
| lnfile vim/ftplugin/perl.vim ~/.vim/ftplugin/perl.vim | lnfile vim/ftplugin/perl.vim            ~/.vim/ftplugin/ | ||||||
| lnfile vim/ftplugin/ruby.vim ~/.vim/ftplugin/ruby.vim | lnfile vim/ftplugin/ruby.vim            ~/.vim/ftplugin/ | ||||||
| 
 | 
 | ||||||
| # Install pathogen | # Install pathogen | ||||||
| if [[ ! -f ~/.vim/autoload/pathogen.vim ]] | if [[ ! -f ~/.vim/autoload/pathogen.vim ]] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue