URI: 
       thome-sweet-home.txt - monochromatic - monochromatic blog: http://blog.z3bra.org
  HTML git clone git://z3bra.org/monochromatic
   DIR Log
   DIR Files
   DIR Refs
       ---
       thome-sweet-home.txt (15304B)
       ---
            1 # Home, sweet home
            2 
            3 28 October, 2013
            4 
            5 ## Summary
            6 
            7 Yes, a summary, because that's gonna be a LONG article.
            8 
            9 * [Introduction](#intro)
           10 * [Window manager](#wm)
           11 * [Terminal](#term)
           12 * [Shell](#sh)
           13 * [CLI tools](#cli)
           14 * [Status bar](#bar)
           15 * [Integration](#setup)
           16 
           17 <h3 id='intro'>Introduction</h3>
           18 
           19 Okay, so you have finally installed your distro of choice, cleaned
           20 the whole setup, installed X.org, xterm and vim...  
           21 
           22 **And now, what?!**
           23 
           24 I've asked myself this question more than I should (probably because
           25 I liking tweaking my desktop, but that's not the point here).  
           26 And I bet that you did too !
           27 
           28 In this post, I'll go through all the mandatory tweak that should be
           29 done to a clean base system. YOUR system, 'cause there is no place
           30 like home.  
           31 Once standing in your ~, starring at your shell prompt, you should
           32 be like <q>Uuuh that is life, eh!</q>
           33 
           34 I'll not wait more to give you my secrets, but please, keep in mind
           35 that these are _MY OPINIONS_ and I'm not asking you to agree
           36 with me. If you feel uncomfortable with some points, just avoid
           37 them. You're not here to feel bad, but to find advices on
           38 **setting up your home!**
           39 
           40 <h3 id='wm'>Window manager</h3>
           41 
           42 This is the most important part of your future environment. It is
           43 the god that will tell all your windows where to go, how to move,
           44 etc.. So you can take a little time to choose a WM, it totally
           45 understandable.
           46 
           47 There are three types of window managers:
           48 
           49 * **Floating** &mdash; windows overlaps
           50 * **Tilling** &mdash; windows are arranged in tiles (kinda like a grid)
           51 * **Dynamics** &mdash; both floating and tilling are possible
           52 * **Aliens** &mdash; Go home WM, you're drunk.
           53 
           54 Floating management is the management style we're all used to,
           55 windows are independent and you can resize/move them freely around
           56 your desktop.  
           57 Tilled window managers arrange the windows depending on what is
           58 currently on your desktop. The windows _CAN'T_ overlap. When
           59 you create a new window, the whole set of window is rearranging to
           60 let the new window find a place (Not always in fact, but that's the
           61 idea behind tilling).  
           62 Finally, dynamic WM can switch between the two managment styles
           63 (most of the time, at cost of complexity and binary size, but that's
           64 just my opinion). Note that most tilling WM are, in fact, dynamic
           65 WM. But the way they manage floating windows is just so poor...  
           66 
           67 Oh, and for the alien part, keep in mind that some WM just don't
           68 manage windows like that. But their behaviors are to specific to be
           69 described here. Just RTFM 'em.
           70 
           71 FYI, here is a non-exhaustive list of window managers I like (F =
           72 floating, T = tilling, D = dynamic... U DON'T SAY!)
           73 
           74 * cwm &mdash; Calm Window Manager (F)
           75 * Ratpoison (A)
           76 * ctwm (F)
           77 * herbstluftwm (T) (<q>Hebrstrutoflutudobleyouhem</q>)
           78 * evilwm (F)
           79 * xmonad (D)
           80 * spectrwm (T)
           81 * ...
           82 
           83 Note that I _DIDN'T_ mentioned AwesomeWM or openbox. beuâh.
           84 
           85 Once you have chosen your WM, go through its manpage/doc, set it up
           86 to look the way you want. Use stuff like [librgba](http://gnome-look.org/content/show.php/Another+Gtk+RGBA+module+?content=100968),
           87 [compton](https://github.com/chjj/compton) to make it
           88 even prettier!  
           89 
           90 [![cwm screenshot](http://pub.z3bra.org/monochromatic/img/thumb/2013-10-28-cwm.jpg)](http://pub.z3bra.org/monochromatic/img/2013-10-28-cwm.jpg)
           91 *Here is a quick CWM setup, using compton and
           92 librgba*
           93 
           94 Oh! A last advice, **do not bind applications through your WM**. Using an
           95 application like [xbindkeys](http://www.nongnu.org/xbindkeys/xbindkeys.html) to
           96 do that is a better idea, as it follow the
           97 [UNIX philosophy](http://www.faqs.org/docs/artu/ch01s06.html), and it will help
           98 you a lot if you want to try another WM.
           99 
          100 <h3 id='term'>Terminal</h3>
          101 
          102 Here we are. The terminal. The central part of the whole setup!
          103 
          104 As an advanced user, you spend a lot of time within the terminal, so it is
          105 important to keep your terminal a pleasant place for your eyes.  
          106 There are, in fact, only two ways to tweak your terminal: **colors and font**.
          107 The goal is to find the best readability/usability/awesomeness ratio.  
          108 I'd recommend that you start from a dark scheme, as it's better for your eyes
          109 by night (But that's just my opinion, light colorschemes can look pretty
          110 good!).  Terminals usually manage up to 256 colors, but you will use only 16
          111 of them:  
          112 
          113 &rarr; [0-7] for normal text  
          114 &rarr; [8-15] for bold text  
          115 Here is the color chart:
          116 
          117 <table>
          118     <tr>
          119         <th></th>
          120         <th>black</th>
          121         <th>red</th>
          122         <th>green</th>
          123         <th>yellow</th>
          124         <th>blue</th>
          125         <th>magenta</th>
          126         <th>cyan</th>
          127         <th>white</th>
          128     </tr>
          129     <tr>
          130         <th>dark</th>
          131         <td>00</td>
          132         <td>01</td>
          133         <td>02</td>
          134         <td>03</td>
          135         <td>04</td>
          136         <td>05</td>
          137         <td>06</td>
          138         <td>07</td>
          139     </tr>
          140     <tr>
          141         <th>light</th>
          142         <td>08</td>
          143         <td>09</td>
          144         <td>10</td>
          145         <td>11</td>
          146         <td>12</td>
          147         <td>13</td>
          148         <td>14</td>
          149         <td>15</td>
          150     </tr>
          151 </table>
          152 
          153 Now, just tweak each color to fit your perfect theme!  
          154 To do so, refer to the manual of your terminal.
          155 
          156 If you don't have one, here is a list of terminal you can use:
          157 
          158 * [rxvt-unicode](http://software.schmorp.de/pkg/rxvt-unicode.html)
          159 * [termite](https://github.com/thestinger/termite/)
          160 * [evilvte](http://www.calno.com/evilvte/)
          161 * [aterm](http://www.afterstep.org/aterm.php)
          162 * [mterm](http://freecode.com/projects/mterm)
          163 
          164 I have stick with rxvt-unicode (urxvt) personnally. I find it pretty
          165 powerfull, light and fast. Also, it can be extended in perl, which
          166 is great (muh URL selection).
          167 
          168 Back to terminal colors! The best way I know to change the terminal
          169 colorscheme, is using the X server resource database (xrdb). But it
          170 does not work with every terminal (it works, at least, with xterm and
          171 urxvt).  
          172 All you have to do, is configure your colors in a file called
          173 `~/.Xresources`, and source it with the command:
          174 
          175     xrdb -load ~/.Xresources
          176 
          177 For example, here is mine (screenshot at the end of the section):
          178 
          179     Xresources
          180 
          181     *background:#222222
          182     *foreground:#e8e9ca
          183 
          184     *color0:    #222222
          185     *color1:    #8b3e2f
          186     *color2:    #526f33
          187     *color3:    #665847
          188     *color4:    #4a708b
          189     *color5:    #7a378b
          190     *color6:    #528b8b
          191     *color7:    #999999
          192 
          193     *color8:    #4c4c4c
          194     *color9:    #d75f00
          195     *color10:   #cee318
          196     *color11:   #eee685
          197     *color12:   #9ac0cd
          198     *color13:   #9f79ee
          199     *color14:   #79cdcd
          200     *color15:   #e8e9ca
          201 
          202 For the font, it's quite the same, but I suggest that you search for
          203 the terms _xft font_, _bitmap fonts_ and _X
          204 resources_ cause it can be a little tricky to understand.
          205 
          206 Quickly, there are two way to draw fonts in your terminal, with, and
          207 without xft. XFT allows you to draw nice fonts and scale them the
          208 way you want, like BitStream Vera Sans, Monospace, etc... But these
          209 are "slow" to draw.
          210 The other method is the one used by TTY, bitmap fonts. Those are
          211 fixed pixeled font that can look odd, but draw fastly.  
          212 Just make a choice.  
          213 To declare a XFT font:
          214 
          215     xft:<font name>:size=<size>
          216 
          217 Bitmap font are declared like this (taken from xfontsel -print, thanks to 
          218 [Gnu42](http://www.reddit.com/r/unixporn/comments/1pf6p4/howto_build_your_graphical_environment_piece_by/cd200mg) 
          219 for the package).  You can then use the xfontsel package, or look for a file
          220 named fonts.dir in your font directory.
          221 
          222     -fndry-fmly-wght-slant-sWdth-astyl-pxlsz-ptSz-resx-resy-spc-avgWdth-rgstry-encdng
          223 
          224 Here is a small example:
          225 
          226     Xresources
          227 
          228     *font: xft:monospace:size=10
          229     *font: -misc-tamsyn-medium-*-*--14-101-*-*-*-*-*
          230 
          231 So, we have seen how to tweak the terminal, let's see what it looks like!
          232 I wrote a small script for the purpose:  
          233 
          234 [![term screenshot](http://pub.z3bra.org/monochromatic/img/thumb/2013-10-28-term.jpg)](http://pub.z3bra.org/monochromatic/img/2013-10-28-term.jpg)
          235 *A terminal running the script
          236 [info.sh](http://pub.z3bra.org/monochromatic/misc/info.sh) that dump 16
          237 colors along system informations*
          238 
          239 <h3 id='sh'>Shell</h3>
          240 
          241 right after seeing the terminal, you can't avoid it's main program: **the shell**.  
          242 If you don't know this already, the shell is the link between the user and the
          243 programs. It's a program you will communicate with to manipulate your system.
          244 An important program tough.  Choose it carefully then. Here is the main shell
          245 list:
          246 
          247 * sh &mdash; The historical shell
          248 * bash &mdash; Improved shell, based on sh
          249 * zsh &mdash; An extremly powerfull shell with a great completion system
          250 * fish &mdash; A user friendly shell, really different from the above
          251 * csh &mdash; The Berkeley UNIX shell
          252 * tcsh &mdash; An improvement of csh
          253 
          254 I personnaly used zsh a lot because it has a feature I like,
          255 the right prompt. also, it's completion system is really great
          256 (argument completion is a good thing to have, trust me..). But I now
          257 use bash again because I don't need much of the features zsh
          258 provide, so that was kinda like using a chainsaw to cut a thin rope.
          259 
          260 Anyway, I'll treat here only the "standard shell": bash   
          261 
          262 The first thing you will see from the shell is its prompt. The
          263 prompt is a set of characters that gives info to the user, and
          264 invite him to input commands. Basically, it looks like this:
          265 
          266     $ 
          267 
          268 Fancy huh ?
          269 The prompt chars are contained in the variable PS1 for
          270 sh/bash, and PROMPT/RPROMPT for zsh.
          271 
          272     $ PS1='z3bra-$ '
          273     z3bra-$
          274 
          275 (You don't have to issue the two command to make it works.)
          276 Take a look at the bash manpage, section "Prompting" for more info
          277 on how to tweak it.
          278 Here is my personnal prompt:
          279 
          280     bashrc
          281 
          282     # Fancy prompt
          283     fg=('\[\e[0;30m\]' '\[\e[0;31m\]' '\[\e[0;32m\]' '\[\e[0;33m\]'
          284         '\[\e[0;34m\]' '\[\e[0;35m\]' '\[\e[0;36m\]' '\[\e[0;37m\]'
          285         '\[\e[1;30m\]' '\[\e[1;31m\]' '\[\e[1;32m\]' '\[\e[1;33m\]'
          286         '\[\e[1;34m\]' '\[\e[1;35m\]' '\[\e[1;36m\]' '\[\e[1;37m\]')
          287     nofg='\[\e[0m\]'
          288 
          289     PS1='';[ -n "$SSH_CLIENT" ] && PS1="${fg[8]}$(hostname|cut -b-2) "
          290     export PS1=" ${PS1}${fg[11]}──── ${nofg}"
          291 
          292 And my old zsh prompt:
          293 
          294     zshrc
          295 
          296     PROMPT=" %{$fg_bold[yellow]%} »  "
          297     RPROMPT="%{$fg[black]%}%M:%{$fg_bold[yellow]%}%~%{$reset_color%}   "
          298 
          299 [![shell screenshot](http://pub.z3bra.org/monochromatic/img/thumb/2013-10-28-shell.jpg)](http://pub.z3bra.org/monochromatic/img/2013-10-28-shell.jpg)
          300 *A few different prompts, from top to bottom: sh, zsh,
          301 bash, zsh*
          302 
          303 <h3 id='cli'>CLI tools</h3>
          304 
          305 The shell is the core of a UNIX/Linux based system. So having a
          306 bunch of fast, light and efficient CLI tools is a must. There are
          307 applications for (almost) everything you do on a daily basis with
          308 you computer: IRC clients, Text editor, Video games, Web browsers,
          309 image viewer, ...  
          310 
          311 Okay, I agree that some of them are not really practical to use
          312 everyday. Mostly when it involve images (web lurking, image
          313 processing, gaming, ...).  
          314 But when you don't need images, **unleash your
          315 shell!**  
          316 Use CLI based app for text-based task. It has many advantages:
          317 
          318 * ALWAYS fit your colorscheme (see [Terminal](#terminal))
          319 * Focus on usability
          320 * Integrate well with your whole setup
          321 * This is fast as hell
          322 * This is powerfull as hell
          323 * You look like a hacker
          324 
          325 I personnaly use [vim](http://vim.org), [irssi](http://irssi.org) and
          326 [mutt](http://mutt.org) on a daily basis.  
          327 As an alternative, take a look at [emacs](https://www.gnu.org/software/emacs/),
          328 [weechat](http://weechat.org/) and
          329 [Alpine](http://sourceforge.net/projects/re-alpine/).
          330 
          331 [![cwm screenshot](http://pub.z3bra.org/monochromatic/img/thumb/2013-10-28-cli.jpg)](http://pub.z3bra.org/monochromatic/img/2013-10-28-cli.jpg)
          332 *Mandatory screenshot of the setup with those apps (and
          333 custom themes).  
          334 top-left: **vim**  
          335 top-right: **mutt**  
          336 bottom-left: **tmux**  
          337 bottom-right: **irssi***
          338 
          339 <h3 id='bar'>Status bar</h3>
          340 
          341 All of this is great, but I think that if you want to check the
          342 time, you're not willing to open a terminal, and type:
          343 
          344     date +%H:%M
          345 
          346 It's not really practical most of the time. The same can apply to
          347 the amount of free space, to current volume level or the number of
          348 unread mails you have.  
          349 That's what status bar are made for. They pick infos for you and
          350 display them in a thin bar on an edge of your screen.  
          351 
          352 My bar of choice is, by far,
          353 [bar ain't recursive](https://github.com/LemonBoy/bar), by Lemon Boy.  
          354 It is light, fast and simple. Exactly how I like it!  the purpose is simple:
          355 
          356 1. Write a script that output a bunch of informations
          357 2. Pipe that script into the bar
          358 3. Run them within an infinite loop!
          359 
          360 That is all you need. For example, if you only need the date in the bar:
          361 
          362     while :; do date; done | bar &
          363 
          364 And there you go!  You can achieve really great looking stuff with that simple
          365 process:  
          366 
          367 [![bar screenshot](http://pub.z3bra.org/monochromatic/img/thumb/2013-10-28-bar.jpg)](http://pub.z3bra.org/monochromatic/img/2013-10-28-bar.jpg)
          368 *You can also choose to put your status bar within a
          369 terminal multiplexer status bar, 
          370 [as phyrne suggested](http://calummacrae.blogspot.fr/2012/12/dropping-status-bars-for-tmux-as-im.html)
          371 in one of his blog post*
          372 
          373 <h3 id='setup'>Integration</h3>
          374 
          375 Now that we potentially have a working desktop, let make it spawn
          376 correctly, using ONLY one file: `~/.xinitrc`.
          377 
          378 That magical file is simply a shell script that is called by default
          379 with `startx`.  In fact, when you proceed this command, it does the following:
          380 
          381     $ startx ~/.xinitrc -- :0
          382 
          383 It source your ~/.xinitrc, and launch it on the Xorg server number
          384 0.
          385 To launch your wm of choice from the xinitrc, just add the command
          386 to launch it in the file, preceded by 'exec'. It will replace the
          387 current process (your shell) by the window manager, so that the
          388 session will terminate with your WM.  
          389 
          390 Okay, now you have the theory. Before starting to pratice, I'll give
          391 you a few hints for a "good" xinitrc (yeah, I love making lists):
          392 
          393 * Launch ONLY session related commands
          394 * Make it evolutive, so that you can spawn multiple X sessions at the same time
          395 * Fork every command, except those that are dependent, to speed up the desktop
          396   spawning
          397 
          398 Finally, here is my own xinitrc
          399 
          400     xinitrc
          401 
          402     #!/bin/bash
          403     #
          404     # ~/.xinitrc
          405     #
          406 
          407     # load nvidia config
          408     nvidia-settings -l
          409 
          410     # Set wallpaper
          411     hsetroot -tile ~/usr/img/bg/stripes.png &
          412 
          413     # default cursor
          414     xsetroot -cursor_name left_ptr &
          415 
          416     function wm() {
          417     # Load X resources
          418     xrdb -load ~/.Xresources &
          419 
          420     # personnal bindings
          421     xbindkeys
          422 
          423     # set WM name
          424     xsetroot -name $1
          425 
          426     #status bar
          427     ~/bin/bar/status.sh & # it acts kinda weirdly
          428 
          429     # Compositing
          430     # enable RGBA module for GTK
          431     export GTK_MODULES=rgba
          432 
          433     #compton -cCb -t-5 -l-5 -r4.2 -o.4
          434     compton -cb -o0
          435 
          436     # spawn window manager
          437     exec $1
          438     }
          439 
          440     [[ -z $1 ]] && wm cwm
          441 
          442     wm $1
          443 
          444 [![final screenshot](http://pub.z3bra.org/monochromatic/img/thumb/2013-10-28-final.jpg)](http://pub.z3bra.org/monochromatic/img/2013-10-28-final.jpg)
          445 *That shot show off the whole setup, with prompt, bar,
          446 applications, etc...  I hope you will like it!*
          447 
          448 ## Conclusion
          449 
          450 The end, finally. That is a damn long article. I have deliberately not expanded
          451 some point by lack of "space". I want this article to end someday.  It will
          452 give you a good start to tweak your own setup, and make it look like
          453 what you want it to look.  
          454 
          455 **Make your environment yours, and have fun doing so!**