Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, January 15, 2013

Short hint for all those who use vim and pathogen

Today, after updating my wokspace to latest version I encounter below error during vim running:
Error detected while processing function pathogen#runtime_append_all_bundles:
line    1:
E121: Undefined variable: source_path
E116: Invalid arguments for function string(source_path).') to pathogen#incubate('.string(source_path.'/{}').')')
E116: Invalid arguments for function 4_warn
Press ENTER or type command to continue
Quick look on pathogen runtime_append_all_bundles function and I found:
call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#incubate('.string(a:1.'/{}').')')
So simply replacing:
call pathogen#runtime_append_all_bundles()
with:
call pathogen#incubate()
in $HOME/.vimrc fix the problem.

Sunday, May 13, 2012

Mutt tutorial part 4 - html mails, address book and other useful features

How mutt can handle mails in html format ? Takling about html mail handling is talking about handling any type of Multipurpose Internet Mail Extensions. Mutt supports handling for all MIME types in one place for all programs. This place is .mailcap file. Googling a little bit I found below mailcap file configuration (kudos to Bart Nagel).
text/html; pandoc -f html -t markdown; copiousoutput; description=HTML Text; test=type pandoc >/dev/null
text/html; lynx -stdin -dump -force_html -width 70; copiousoutput; description=HTML Text; test=type lynx >/dev/null
text/html; w3m -dump -T text/html -cols 70; copiousoutput; description=HTML Text; test=type w3m >/dev/null
text/html; html2text -width 70; copiousoutput; description=HTML Text; test=type html2text >/dev/null
Of course we need to install all applications to make mailcap work correct:
sudo apt-get install pandoc lynx w3m html2text
To bring address book functionality to mutt we need abook application:
sudo apt-get install abook
Also few new line in $HOME/.muttrc will be needed:
# add alias file for addresses
set alias_file=~/.mutt/alias
source ~/.mutt/alias
# configure addressbook
set query_command= "abook --mutt-query '%s'"
macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
Adding new address simply create entry in alias file. During adding new alias abook asks about alias name, e-mail address, personal name and confirmation for given data. Some this fields could be filled automatically by interaction between abook and mutt. Of course file $HOME/.mutt/alias have to exist before running mutt:
touch $HOME/.mutt/alias
To access saved aliases simply click <Tab> button in cc, to or bcc filed.
There is few more options that I found useful. To find it please go to my workspace scripts at github. Also if you have any issues with the configuration or comments please let me know by commenting below the post.

Mutt tutorial part 3 - sidebar, URLs in e-mails

Information in this post came from lunar linux page. Kudos to its author. In this post I want to discuss two topics: sidebar and how to open urls form inside mutt. Sidebar is mutt feature delivered in mutt-patched package in Debian. It cause to split standard mutt window in two parts. In first we can find list of folders defined in the $HOME/.muttrc file, second window is a known old window with the list of posts. Mutt window with sidebar looks like on the picture below:
To use side bar we need to install mutt-patched packed in Debian:
sudo apt-get install mutt-patched
To make side bar more accessible I use default settings from lunar linux page. Add below lines to $HOME/.muttrc:
set sidebar_width       = 30
set sidebar_visible     = yes
color sidebar_new yellow default
bind index CP sidebar-prev
bind index CN sidebar-next
bind index CO sidebar-open
bind pager CP sidebar-prev
bind pager CN sidebar-next
bind pager CO sidebar-open
First line sets width of side bar it depends on how long are your folder names. Second line makes sidebar by default visible. Third makes folders with new messages yellow. Other lines create shortcuts for navigating sidebar. Note that C is not Ctrl but uppercase 'c' key. Second topic I want to discuss is how to open urls from inside e-mails. To do this we can use tip from mutt site. As it said we need urlview application:
sudo apt-get install urlview
To correctly configure this tool you need to create $HOME/.urlview file. So:
vim $HOME/.urlview
In this file we define two things. First will be regular expression which match urls and second will be command line to run when regexp was matched. File looks like below:
REGEXP (((https?|ftp|gopher)://|(mailto|file|news):)[^’ <>"]+|(www|web|w3).[-a-z0-9.]+)[^’ .,;<>":]
COMMAND chromium %s
Chromuim is my browser of choice but you can use firefox, lynx or anything you want.

Mutt tutorial part 2 - secure login

This is second post of mutt tutorial series. As in the previous post for below information I need to thank Kousik for posts about gpg and using it with mutt. But probably the most important to simplify this method was Fau comment here. So going to the point of secure login for mutt we need gpg. First of all we need to install it by simply:
sudo apt-get install gpg
After that we generate our keys by:
gpg --gen-key
I choose all default answers. So first is key type: 'RSA and RSA'. Second - keysize: 2048. Third - time for key expiration: '0 = key does not expire'. After that you need to identify your key with some data. This data will be used to find your key so IMHO it should be short and simple but meaningful. At the end of this process you will be asked about pass phrase, which will be used to decrypt files encrypted with generated key. When you end with key generation you can encrypt file with passwords. Best way to do this is to write some script that will be sourced by mutt after decryption. For storing passwords I create directory in my $HOME:
mkdir $HOME/.passwd
Inside this directory I create text file with the script, which look like below:
vim $HOME/.passwd/mutt.txt
set my_isp1 = "password1"
set my_isp2 = "password2"
set my_isp3 = "password3"
This script of course mean to set value of variable name my_isp{1,2,3} to some password string. Remember to use 'my_' prefix because this is the way that user variables should be defined in mutt scripts. After writing this file we need to encrypt it.
gpg -e -o mutt.gpg mutt.txt
Now we should delete txt file. To use our newly created encrypted password script we need to add some lines to $HOME/.muttrc. So:
vim $HOME/.muttrc
Line that we need before sourcing encrypted scripts is declaration of variables in the script:
set my_isp1 = ""
set my_isp2 = ""
set my_isp3 = ""
After this line we can source and decrypt out file with the passwords:
source "gpg --textmode -d ~/.passwd/mutt.gpg |"
At the end wee need to replace all out plain text passwords (smtp_pass and imap_pass variables) with variables defined in out encrypted file. This settings will cause that mutt during start will run gpg to ask about password to decrypt password script file. In the next post I will discuss mutt with sidebar and how to open html files from inside mutt.

Mutt tutorial part 1 - setup IMAP account

Mutt is one of those programs that make people call you a linux geek, nerd or a snob. This is because using TUI or command line tools in world of fancy GUI for most people is wierd. What's so great about mutt? I probably still have not found much of its advantages, but at first glance we can notice a few things. First, it keeps Unix convention of small programs for specific task "Make each program to one thing well" or KISS. This means that mutt is only MUA, which is used to retrieve e-mails and for other tasks you need to use another application. However, due to the philosophy most applications are well suited to each other and usually everything works good. So you can easily combine it with Vim as the mail editor, abook as a address book, urlview as a browser launcher for html and graphics elements and so on. Third, it has support for IMAP which gives very nice usage model for most of e-mail account providers. Fourth, is used by such notables as Greg Kroah-Hartman and as kernel documentation suggest by other kernel developers. So lets start to discover mutt. Below I will discuss some basic features that until now (few days of using mutt) I found useful.
  1. Big kudos to Shinobu for this post it helps me a lot. So first of all we need support for multiple accounts. In my case I have 4 accounts. Three of them got working IMAP access. 4th provider screw up something and access to IMAP server doesn't work so I need to workaround this with one of the Gmail features. At the beginning we create $HOME/.muttrc file:
    vim $HOME/.muttrc
    IMAP account configuration for looks like that:
    # unset important variables
    account-hook . "unset imap_user; unset imap_pass"
    account-hook        "imaps://<account_name>@<imap_server_address>/" "\
        set imap_user   = <e-mail_address> \
            imap_pass   = <e-mail_password>"
    
    # Setup for <e-mail_address>:
    set folder          = imaps://<account_name>@<imap_server_address>/
    # setup needed folders
    mailboxes           = +INBOX =<folder_name>
    set spoolfile       = +INBOX
    folder-hook         imaps://<account_name>@<imap_server_address>/ "\ 
        set folder      = imaps://<account_name>@<imap_server_address>/ \
            spoolfile   = +INBOX \
            postponed   = +[Gmail]/Drafts \
            record      = +[Gmail]/'Sent Mail' \
            from        = '<your_name> <e-mail_address> ' \
            realname    = '<real_name>' \
            smtp_url    = smtps://<account_name>@<smpt_server_address> \
            smtp_pass   = <e-mail_password>"
    
    <account_name> - for foo.bar@gmail.com it will be foo.bar <imap_server_address> - this information you can get from your e-mail provider help pages or from the settings of web e-mail client, for Gmail it is imap.gmail.com
    <e-mail_address> - your e-mail address
    <e-mail_password> - your e-mail password, later we will discuss how to store this more secure than plain text :)
    <folder_name> - any folder (for gmail account also filters) you have on you IMAP account, so for gmail account it could be Drafts, Starred, Important or others.
    <your_name> - your real name or nick anything you want to show in from field
    <real_name> - could be the same as <your_name>
    <smpt_server_address> - your SMTP server address, for gmail users it will be smtp.gmail.com
  2. If your e-mail provider have only pop3 access and you have gmail account you can use one of gmail account features to make your pop3 account visible as a IMAP folder. To do this got to Settings -> Accounts and Import and in the section "Check mail from other accounts" add your POP3 account. After that make sure to label your mails from POP3 account. Try to not use '@' in the label name because this cause problems during mutt configuration. If you set label for your POP3 account check if your label in Label tab have "Show in IMAP" marked, if yes everything was set correctly. To use this label in mutt simply add another <folder_name> to mailboxes line.

Friday, April 6, 2012

How to download videos from videos.linux.com

Therefore, I'm leaving for the Easter holidays I wanted to download some lecture on embedded systems, which was presented at the 2012 Embedded Linux Conference. Although I regret I found that I could not find as good quality copy in the network as on the Linux Foundation page. It is unfortunate that linux.com site does not have the possibility of direct downloading video files. But there is a workaround. Follow below tutorial:

  1. Go to page with video. For example:  http://video.linux.com/videos/to-provide-a-long-term-stable-linux-for-industry
  2. Click play on the video and if you using Chrome browser right click on player window and inspect this element. Result should look like that: 


  3. Expand div tag marked in red on screenshot above. If video was start you should see video tag which contain two links to video files mp4 and webm. Screen shot below shows hot it should look like:


These links are only temporary, so if you want to use them do it as soon as possible. The sad part of all is that the organization intended to promote one of the most libertarian solutions in software history does not provide materials for download.

Monday, February 20, 2012

Improve productivity by tracking work environment with git - vim

In this post I try to describe my vim configuration procedure and how it is connected with git. The whole concept is based on keeping all the configuration files in a separate directory. These files are connected using symbolic links in places where system or application requires it (eg $HOME/.vimrc -> /home/jdoe/workspace/dotfiles/vimrc). So first let's create local directory for vim:
cd ~/workspace/dotfiles;mkdir vim

  1. Pathogen

  2. The first plugin that will be installed is pathogen created by tpope and accessible through github. Pathogen is a vim script to manage all vim plugins with ease. Below line add pathogen as submodule to our workspace repository created in previous post:
    git submodule add https://github.com/tpope/vim-pathogen.git dotfiles/vim/pathogen
    Initialise repository and update it:
    git submodule init && git submodule update
    Create additional directories need to complete pathogen installation, change directory to autoload:
    cd dotfiles/vim;mkdir {autoload,bundle};cd autoload
    In autoload directory pathogen should be installed, bundle directory is a place for all plugins installed in future. Finally we need to link vim script from pathogen submodule to current directory (dotfiles/vim/autoload):
    ln -s ../pathogen/autoload/pathogen.vim .
    Directory structure should look like below:
                    pietrushnic@eriador:~/workspace/dotfiles$ tree
                    .
                    └── vim
                        ├── autoload
                        │   └── pathogen.vim -> ../pathogen/autoload/pathogen.vim
                        ├── bundle
                        └── pathogen
                            ├── autoload
                            │   └── pathogen.vim
                            └── README.markdown
    
    At the end of pathogen installation few lines to $HOME/.vimrc should be added. Of course following rules about dotfiles management .vimrc should be created as separate file in ~/workspace/dotfiles and linked to $HOME/.vimrc.
    touch vimrc;ln -s $PWD/vimrc $HOME/.vimrc
    Add below lines to $HOME/.vimrc
     call pathogen#infect()
    call pathogen#runtime_append_all_bundles()
    call pathogen#helptags()
    syntax on
    filetype plugin indent on
    

  3. Fuzzyfinder
  4. This is second plugin without which I cannot work. It speeds up searching though files, directories and tags. Has multiple useful features. RTFM if you want knew them. I will be also added as a git submodule:
    git submodule add https://github.com/vim-scripts/FuzzyFinder.git dotfiles/vim/bundle/fuzzyfinder
    Additional plugin is needed to correctly install fuzzyfinder:
    git submodule add https://github.com/vim-scripts/L9.git dotfiles/vim/bundle/l9
    Initialize and update submodules:
    git submodule init && git submodule update
    Configuration I suggest to configure fuzzyfinder with accordance to example provided in help. 
    • Run vim and type :h fuf@en<Enter>. 
    • Choose tag fuf-vimrc-example and press Ctrl-]. 
    • Mark whole keybindings copy and paste to ~/.vimrc
Right now I think it is enough with vim configuration. Of course I use plenty of other plugins but I don't have to time to describe my them all (maybe in future posts). Don't forget to commit your changes, there could be a lot of them, however, to deal with the distribution of these changes and improve your skills try to use git add -p interface, suggesting after linux code style - each commit should contain separate logical part of the changes, personally I add prefix to my commits (eg . vim, git, etc.) to ease deal with git log.
Notes:
  • vim helpfiles generates tags files, which should be ignored by git, so I recommend to create .gitignore in every module with blow content:
  • .gitignore
    tags*
  • by default fuzzyfinder operate on unfriendly color palette espessicaly when using it through putty, highlighted pattern could be changed by added below lines to .vimrc (9 = black)
  • " fuzzy-finder - fix colors
    highlight PmenuSel ctermbg=9

Hostname generator

Many times happened that I spend time, during the installation of the new system, whether it be a virtual physical machine, wondering about it's hostname. One day I asked myself the trouble searching for host name generator. Best I could find (currently second in the results of google) is rospo.net. It gives you the choice of category for the host name. My favorite, as a fan of fantasy is "Characters from Tolkien". Although the category name does not reflect the truth, because in addition also includes a set of known sites in middlearth and more. So I recommend:

Sunday, February 19, 2012

Improve productivity by tracking work environment with git - preparation

Below is first post from series in which I want to describe my experience gained in attempt to enhance my productivity by using git to control the contents of some files in my home directory. The first step to improve the productivity is good organization of working environment. It happens very often that I work on multiple machines both physical and virtual. Therefore I need a good mechanism to share knowledge, experience, code, configuration and many other things. Configuration described below is only an example that actually fits my way of working.
First of all simple concept of directory structure is needed. Let's start with:
$HOME/workspace
        |- dotfiles
        |- blog
mkdir -p $HOME/workspace/blog;mkdir -p $HOME/workspace/dotfiles
cd workspace
Write some files (i.e. for your blog) with your favourite editor, initialize repository and prepare first commit
git init
git add .;git commit -m "Initial commit for environment tracking"
To avoid information about untracked vim swp files add $HOME/workspace/.gitignore with following content:
.gitignore
*.swp

Wednesday, February 15, 2012

Set irssi under debian to use freenode server

Very short manual on how to set up irssi to work with freenode servers.
Fist, install irssi:
sudo apt-get install irssi
Run:
irssi
For freenode write:
/connect holmes.freenode.net
Send register command for youe {nickname} and add information about your {e-mail}:
/msg nickserv register {nickname} {e-mail}
Copy and paste line, which you get from freenode registration server to your mailbox, to irssi. After that add freenode network:
/network add freenode
Add what should be automaticali send to server after connecting, remeber to correctly write your {nickname} and {password}, password will be stored in plain text:
/network add -autosendcmd '^nick {nickname};/msg nickserv identify {password}' freenode
Auto-connect everytime when irssi will be run:
/server ADD -auto -network freenode holmes.freenode.net 6667
Channel autologin:
/channel ADD -auto #debian freenode
After all we should save settings:
/save
That's all, enjoy!