Qball's Weblog
Updated my netbook
Took some effort to get everything installed the way I want, but it is operational again:
I also my ConfigFile script again.
What this does link config files from I keep in a directory (that is a git repository) to the right location.
It will created the needed directories and link the files into the right place.
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
#!/bin/bash CONFIG_FILE="config" ### # Link dir a to b ## function link_dir() { # Expand input file in=`pwd`/$1 # Expand output file out=${2/#~/$HOME} # Check if directory exists, if not create it. if [ ! -d "$in" ]; then echo -e "\t** input is not a directory" return; fi # Check if destination is a file if [ -f "$out" ]; then echo -e "\t*\t$out is a file. Quitting..." return fi # Test if it is a symbolic link, if so remove it if [ -d "$out" ]; then echo -e "\t*\t$out is a directory. Removing..." rm -r "$out" fi echo -e "\t*\tLinking $in -> $out" ln -s "$in" "$out" } ### # Link file a to b ## function link_file() { # Expand input file in=`pwd`/$1 # Expand output file out=${2/#~/$HOME} # Get the dirname dir=$(dirname $out) # Check if directory exists, if not create it. if [ ! -d "$dir" ]; then echo -e "\t*\t$dir does not exists, creating" mkdir -p "$dir" fi # Test if it is a file, if so remove it if [ -f "$out" ]; then echo -e "\t*\t$out file exits. Removing..." unlink "$out" fi # Test if it is a symbolic link, if so remove it if [ -h "$out" ]; then echo -e "\t*\t$out symbolic link exits: Removing..." unlink "$out" fi echo -e "\t*\tLinking $in -> $out" ln -s "$in" "$out" } ## # This function starts processing the subdirectory ## function subdirectory_linker() { # enter the directory pushd "$1" > /dev/null # Check if the config file is there if [ -r "${CONFIG_FILE}" ]; then echo "Parsing config file" for file in $( cat "${CONFIG_FILE}"); do # Split the config line into command, intput, output CODE=${file%:*:*} TEMP_INPUT=${file#*:} INPUT=${TEMP_INPUT%:*} FILE=${file#*:*:} # Check the type of action todo, for now l exists, linking case "${CODE}" in l) echo -e "#\tSetting up file "$INPUT" -> "$FILE link_file "$INPUT" "$FILE" ;; ld) echo -e "#\tSetting up dir $INPUT -> $FILE" link_dir "$INPUT" "$FILE" ;; esac done else echo "No config file in "$1 fi # Leave directory popd > /dev/null } ## Iterate through all the directories. ## The idea is every dotfile, or set of dotfiles have it own subdir. # iterate all directories for a in $(ls -d */); do echo Examining directory: $a subdirectory_linker "$a" done |
it will look for subdirectories read the config file, based on the info in there it will link the files.
Example:<pre lang="ini" line=1>l:vimrc:~/.vimrc l:vimrc:~/.gvimrc ld:vimdir:~/.vim </pre>
Syntax is very simple:
l:file1:file2
means link file2 to file1
ld:dir1:dir2
is link dir2 to dir1