Users browsing this thread: 3 Guest(s)
josuah
Long time nixers
I have a few scripts I use everyday, but no one automate anything in the background.

This is really not administration nor security, only for the "and so on"...

The only two thing I currently automate are:

Tags in the terminal window manager DVTM, just like [/url]: .profile


Code:
tag()
{
    local tag="$1"
    local name="$2"
    local cmd="$3"
    shift 3

    [ -p "$DVTM_CMD_FIFO" ] && printf 'tag%s\n' "$tag" >> "$DVTM_CMD_FIFO"
    printf '\033[0m\033]0;%s\007' "$name"
    $cmd $@
}

This one set the tag, just like in dwm, printing the name of a function "tag#", with # being a tag number, to a named pipe (a FIFO), that dvtm reads for automation.

The functions must be declared in the config.h with something like:

Code:
static Cmd commands[] = {
    { "create", { create, { NULL    } } },
    { "tag1",   { tag,    { tags[0] } } },
    { "tag2",   { tag,    { tags[1] } } },
    { "tag3",   { tag,    { tags[2] } } },
    { "tag4",   { tag,    { tags[3] } } },
    { "tag5",   { tag,    { tags[4] } } },
    { "tag6",   { tag,    { tags[5] } } },
    { "tag7",   { tag,    { tags[6] } } },
};

Then, I set alias for most used software, to open them in dedicated tag immediately: [url=github.com/sshbio/dot/raw/master/.profile].profile

Code:
alias    vis='tag 2 vis    $VISUAL'
alias    web='tag 3 web    $BROWSER'
alias    man='tag 3 man    man'
alias    irc='tag 4 irc    irc'
alias   mail='tag 4 mail   mail'
alias    vol='tag 5 volume "alsamixer -c 1"'
alias   grex='tag 6 grex   ssh josuahdemangeon@grex.org'

Finally, whenever I return from the program to the shell, I tag it automatically to the "shell" tag by calling the <code>tag</code> function in my PS1:

Code:
export PS1='$(tag 1 "${PWD/$HOME/~}" "")> '

PS: DVTM has to be started with the -c option to set the name of the named pipe to listen from:
Code:
dvtm -c <whatever fifo>


Compilation. I have a few projects I prefer to compile myself, like if I want to change one of the files (like the config.h), apply a patch (like for dwm, st, or if I made my own patch, edited the source).


Then I can keep my few "custom" software up to date, without having to download .tar.gz > extract > compile each software the way it needs to > install it in my custom $PREFIX.

The way it is implemented is quite dumb:

Code:
source config dir
|_ one dir per project
|  |_ at least the build.sh script
|  |_ eventually other resources, used by the build.sh script, like config.h, or patches
|_ one default build script, as for most software, this just works:

build()
{
    for patch in $(find "$DOT/src/$1" -name '*.diff')
    do patch -p1 < "$patch"
    done

    [ -f "$DOT"/src/"$1"/config.mk ] && cp -f "$DOT"/src/"$1"/config.mk .
    [ -f "$DOT"/src/"$1"/config.h  ] && cp -f "$DOT"/src/"$1"/config.h  .
    [ -f ./autogen.sh              ] && ./autogen.sh
    [ -f ./configure               ] && ./configure --prefix="$PREFIX"
    
    make
    make prefix="$PREFIX" PREFIX="$PREFIX" install clean
    return 0
}

Each build.sh script has:

- One commented line with a description.
- One <code>tar</code> variable with an url to a .tar.gz archive to the source.
- Eventually a <code>build()</code> function, if the default one does not work.



Messages In This Thread
Automating tasks - by sagittarius - 17-06-2016, 09:03 AM
RE: Automating tasks - by venam - 17-06-2016, 04:37 PM
RE: Automating tasks - by josuah - 17-06-2016, 08:00 PM
RE: Automating tasks - by pranomostro - 17-06-2016, 11:26 PM
RE: Automating tasks - by venam - 18-06-2016, 06:19 AM
RE: Automating tasks - by josuah - 18-06-2016, 08:12 AM
RE: Automating tasks - by pranomostro - 18-06-2016, 11:39 AM