monochromatic

monochromatic blog: http://blog.z3bra.org
git clone git://z3bra.org/monochromatic
Log | Files | Refs

home-sweet-home.txt (15523B)


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