git bash prompt

posted by alexis reigel on july 05, 2013

Hi.

I tried many different bash git prompt solutions, all of which were either too complicated, too buggy or too ugly. So…

I didn’t want to invent too much myself, so I used the git prompt provided by git as a basis. This script does all the magic already, so the only thing left to do was to make it look nicer. This is the whole section in my .bash_profile:

# bash git prompt
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="verbose"

git_current_branch_name="\$(__git_ps1 '%s' | sed 's/ .\+//' | sed -e 's/[\\\\/&]/\\\\\\\\&/g')"
git_status_substitutes=(
    "s/$git_current_branch_name//;" # remove branch temporarily
    "s/u//;" # upstream
    "s/+\([0-9]\+\)/▴\1/;" # outgoing
    "s/-\([0-9]\+\)/▾\1/;" # incoming
    "s/%/?/;" # untracked
    "s/+/✓/;" # staged
    "s/*/✕/;" # unstaged
    "s/\(.\+\)/($git_current_branch_name\1)/;" # insert branch again
)
git_status_command="\$(__git_ps1 '%s'| sed \"${git_status_substitutes[@]}\")"

if [ "$color_prompt" = yes ]; then
PS1="${debian_chroot:+($debian_chroot)}\[\033[0;37m\] \w \[\033[34m\]$git_status_command\[\033[37m\]\$\[\033[00m\] "
else
PS1="${debian_chroot:+($debian_chroot)} \w $git_status_command\$ "
fi
unset git_status_substitutes git_status_command git_current_branch_name

And now, step by step:

GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="verbose"
git_current_branch_name="\$(__git_ps1 '%s' | sed 's/ .\+//;s/(//')"
git_status_substitutes=(
    "s/$git_current_branch_name //;" # remove branch temporarily
    "s/u//;" # upstream
    "s/+\([0-9]\+\)/▴\1/;" # outgoing
    "s/-\([0-9]\+\)/▾\1/;" # incoming
    "s/%/?/;" # untracked
    "s/+/✓/;" # staged
    "s/*/✕/;" # unstaged
    "s/\(.\+\)/($git_current_branch_name \1)/;" # insert branch again
)
git_status_command="\$(__git_ps1 '%s'| sed \"${git_status_substitutes[@]}\")"
if [ "$color_prompt" = yes ]; then
    PS1="${debian_chroot:+($debian_chroot)}\[\033[0;37m\] \w \[\033[34m\]$git_status_command\[\033[37m\]\$\[\033[00m\] "
else
    PS1="${debian_chroot:+($debian_chroot)} \w $git_status_command\$ "
fi

The final output looks like this:

~/src/dotfiles (master ✕✓? ▴1▾5)$

The original output of __git_ps1 looks like this, which is much more cryptic:

~/src/dotfiles (master *+% u+1-5)$

The meaning of the symbols:

Unstaged changes
Staged changes
? Untracked files
▴1 One changeset ahead of remote
▾5 Five changesets behind remote
= No difference to remote

You can see the whole thing in action in my .bash_profile.

how to generate a webfont kit with open source tools

posted by alexis reigel on august 06, 2012

There are some web based services that convert fonts to a webfont package, the most popular of which is the fontsquirrel font-face generator. For our metaflop project I was looking for a service api that i could call from within our application. Since i didn’t find one I was attempting to build the whole webfont generation by collecting tools that could do the job.

Font types

To create a webfont kit that works on all browsers we need to generate several different font types:

Tool chain

The following tools are required to generate all the needed font types. I assume that you have your font as otf. If you have a ttf, just switch ttf with otf in the following statements:

The very simple FontForge script (ttf-svg.pe) looks like this:
Open($1)
Generate($1:r + ".ttf")
Generate($1:r + ".svg")
# outputs font.ttf, font.svg
$ fontforge -script ttf-svg.pe font.otf
# outputs font.woff
$ sfnt2woff font.otf
$ ttf2eot font.ttf > font.eot

CSS

The css declaration is based on Fontspring’s bulletproof @font-face syntax and is the same syntax as used by fontsquirrel.

@font-face {
    font-family: 'YourFont';
    src: url('YourFont.eot'); /* IE 9 Compatibility Mode */
    src: url('YourFont.eot?#iefix') format('embedded-opentype'), /* IE < 9 */
         url('YourFont.woff') format('woff'), /* Firefox >= 3.6, any other modern browser */
         url('YourFont.ttf') format('truetype'), /* Safari, Android, iOS */
         url('YourFont.svg#YourFont') format('svg'); /* Chrome < 4, Legacy iOS */
}

That’s it. Remember though that you should only convert fonts are legally eligible for web embedding.

windows console: spawn new process

posted by alexis reigel on january 19, 2011

Under linux spawning a new process is as easy as appending an & to the command. In windows it’s not (obviously). I pretty quickly found out about the start command. Not as elegant as the linux version, but still pretty intuitive. Or, wait, not? It took me half a decade to find out how to use it properly.

First i had a look at the help output, which can be invoked by the switch /?. I’m not 100% sure, but i have in mind that this switch isn’t really standardized, i think I also had to use /h or /help in the past. Anyway, that’s not the sad part yet.

console start

Reading through that, all you have to do is call start my_command. Easy huh? No. It’s not.

After digging around this article lead me to the solution: “title: Text for the CMD window title bar (required)”. Title! Required!
Let me say that again. Title! Required!
First thought: Why? Why is a title required? A title is clearly something optional, especially when you’re starting a GUI application.
Second thought: Why? Why is that “required” not stated as such in the help output? Not the slightest hint in the help output. And furthermore, isn’t it a convention that required parameters are NOT surrounded by brackets? Don’t brackets mean “optional”? Apparently, in the windows tooling environment all this does not apply.

I know, windows is a GUI centered OS, and therefore the console didn’t evolve as nicely as it did in other OS’s. Nevertheless, every time I have to work on a console or write a batch file it gives me the creeps. Everything is so unbelievably clumsy. At least I found out about the Console project, which is a pretty decent replacement for the windows console. Copy/paste works as desired with keyboard shortcuts and you can resize the window. Resize the window! How cool is that! But that’s a different story…