~mapperr/dfl

7adf922a7c0b774b65c8b0c22be05865820b3e69 — mapperr 4 years ago 40fd8ae
Add cloning and jumping
2 files changed, 90 insertions(+), 19 deletions(-)

M README.md
M dfl
M README.md => README.md +34 -9
@@ 9,15 9,16 @@ It, well, links your dotfiles to your HOME directory.

## Dotfiles

Just clone this repo, `cd` in it and put your dotfiles in a `dfl/dotfiles/default` directory, without the dot.
Just clone this repo, `cd` in it and put your dotfiles in a `dotfiles/default` directory, without the dot.

Then run:

`dfl link`
 `dfl link` or `dfl l`

That's it.

It works with directories too:

It works with dotdirectories:

`dotfiles/default/.config/rofi/config.rasi` will be linked to `$HOME/.config/rasi/config.rasi`



@@ 25,7 26,7 @@ If the path does not exits it will mkdir it for you.

If something that is not a link exists it will ask nicely what to do.

The `dotfiles` directory is gitignored, so you can even `git init` another repo in it.
The `dotfiles` directory is gitignored, so, if you didn't do that already, you can `git init` another repo in it.

Or you can symlink your existing dotfiles folder as `/path/to/dfl/dotfiles`.



@@ 41,7 42,7 @@ they will be linked after the `default` ones, and, if `dotfiles` is a git repo, 
If you need some 'overrides', put them in a new directory, e.g. `dotfiles/fluxbox`, and pass it to the script as an argument,
like this:

`dfl link fluxbox`
`dfl l fluxbox`

It will link `default`, then `secrets` and then the `fluxbox` directory, overriding existing links.



@@ 58,15 59,39 @@ that translates in you need some dotfiles to have different content than the usu
It's clean, does not leave broken symlinks all around.


## Git
## Utilities

### Git

You can commit and push your dotfiles directly with `dfl`!
If you have your dotfiles on some git repo you can do a `dfl clone <your repo>`.
It will clone you repo in the `dotfiles` dir, backupping the existing one.

Just:
If you cloned your repo, moved from another directory or just `git init` it
you can commit and push your dotfiles directly with `dfl`:

`dfl git <whatever git command and arguments>`

it `cd` in your `dotfiles` directory and execute the `git` part.

Handy, isn't it? : )
So you can hack your `~/.vimrc` and do:

`dfl g commit -am 'Add awesomeness' && dfl g push`

from wherever you are. Handy, isn't it? : )

### Jumping and dotfiles path

If you have to hack your `overrides` directories, check something, or just dumb around,
you can jump directly in your `dotfiles` directory with `. dfl cd` or `. dfl j`.

Note the dot. I know, dot-this, dot-that, dot-net (eheheh, I'm too funny :-| ).
That dot is there because I cannot change the directory of a parent shell from its child shell.

Another way of doing this is:

    cd `dfl d`

`dfl d` prints your dotfiles directory absolute path.

Ok, it's not that awesome, but, hey, ¯\_(ツ)_/¯.


M dfl => dfl +56 -10
@@ 30,6 30,8 @@ dotfiles_dir_abs="$SCRIPT_DIR/$dotfiles_dir"
track_file_abs="$SCRIPT_DIR/$track_filename"
untrack_file_abs="$SCRIPT_DIR/.untrack"

backup_suffix="-dflbak"

logd() {
    local msg="$1"
    test "$debug" = "true" && echo "$msg"


@@ 63,10 65,10 @@ process_file() {
            rm -f $target_filepath
        else
            echo "WARNING: [$target_filepath] is present and is not a link"
            echo -n "do you want to replace it with a link? (I'll backup it as [$target_filepath~]) (y/n) "
            echo -n "do you want to replace it with a link? (I'll backup it as [$target_filepath$backup_suffix]) (y/n) "
            read c
            if [ "$c" = "y" ]; then
                mv $target_filepath $target_filepath~
                mv $target_filepath $target_filepath$backup_suffix
                if [ ! $? = 0 ]; then
                    echo "ERROR: cannot backup [$target_filepath], I will not link it"
                    return


@@ 173,11 175,22 @@ process_profile() {
}

helpmsg() {
    echo "Usage: `basename $0` [-v] [link [profile_name] | git [git_arguments]]
    echo "Usage: `basename $0` [-v] <command>
    Commands:
        l, link [profile_name]
            links dotfiles in default, secrets and, eventually, profile_name directories, in this order

        g, git [git_arguments]
            runs git commands in the dotfiles directory

        clone <git repository>
            clone a git repo in the dotfile directory, backupping the eventual existing one

        d
            prints the dotfiles directory absolute path

    -v  -  activate verbose mode
    link  -  links dotfiles in default, secrets and, eventually, profile_name directories, in this order
    git [git_arguments]  -  runs git commands in the dotfiles directory
    Options:
        -v  -  activate verbose mode
"
}



@@ 192,18 205,51 @@ if [ "$command" = "-v" ]; then
fi


if [ "$command" = "git" ]; then
if [ "$command" = "g" ] || [ "$command" = "git" ]; then

    shift
    cd $SCRIPT_DIR/$dotfiles_dir > /dev/null
    cd $dotfiles_dir_abs > /dev/null
    git $@
    cd - >/dev/null

elif [ "$command" = "link" ]; then
elif [ "$command" = "cd" ] || [ "$command" = "j" ]; then

    cd "$dotfiles_dir_abs"

elif [ "$command" = "d" ]; then

    echo "$dotfiles_dir_abs"

elif [ "$command" = "clone" ]; then

    shift
    repo="$1"
    if [ -d "$dotfiles_dir_abs" ]; then
        echo -n "Backupping dotfiles current dir... "
        mv $dotfiles_dir_abs $dotfiles_dir_abs$backup_suffix
        if [ $? -ne 0 ]; then
            echo "ERROR: Cannot backup $directory_abs, aborting" >&2
            exit 1
        fi
        echo "done."
    fi
    cd $SCRIPT_DIR >/dev/null
    dotfiles_cloned_dir="dotfiles-cloned"
    git clone "$repo" $dotfiles_cloned_dir
    if [ $? -ne 0 ]; then
        echo "ERROR: Cannot clone repo [$repo], rollbacking" >&2
        rm -rf $dotfiles_cloned_dir
        mv $dotfiles_dir_abs$backup_suffix $dotfiles_dir_abs
        exit 1
    fi
    mv $dotfiles_cloned_dir $dotfiles_dir
    cd - >/dev/null

elif [ "$command" = "l" ] || [ "$command" = "link" ]; then

    shift
    profile="$1"
    cd $SCRIPT_DIR/$dotfiles_dir > /dev/null
    cd $dotfiles_dir_abs > /dev/null
    test -d $default_profile_name && process_profile $default_profile_name
    test -d $secrets_profile_name && process_profile $secrets_profile_name
    if [ ! -z "$profile" ]; then