Posts mit dem Label English werden angezeigt. Alle Posts anzeigen
Posts mit dem Label English werden angezeigt. Alle Posts anzeigen

Freitag, August 10, 2012

XMonad and Org-Mode

After a while playing with XMonad and Org-Mode in Emacs I wrote a function for XMonad to start a Note-File with Emacs in XMonad.

First of all I will have a prompt which shows me all the current org-files in a given directory and then I will select one of the shown files or create a new one.

The following function will produce this prompt and shows me alle available org-files in a given directory.

firingOrgPrompt :: FilePath -> X ()
firingOrgPrompt path = do
  files <- liftIO $ getDirectoryContents path
  inputPromptWithCompl defaultXP "Org" 
    (mkComplFunFromList $ filterOrg files) ?+ (openOrgFile path)
    where openOrgFile p f = spawn (emacsClient ++ p ++ "/" ++ f)
          filterOrg f = filter (endswith ".org") f

After writing this function you will define some keyboard shortcuts in your xmonad.hs file.

myKeys = \c -> newKeys c `M.union` keys defaultConfig c
newKeys (XConfig {modMask = modm}) = M.fromList $
   [ ((modm, xK_n), firingOrgPrompt (wikiRootPath ++ "notes")) ]

After that you have to define the variable emacsClient and wikiRootPath. The variable emacsClient could alse be the function getEditor.

After reloading your XMonad you could hit M-n and you get a prompt where you could select one of those org-files.

Donnerstag, Februar 23, 2012

Working with ssh-agent

For checking some git repositories it is very uncomfortable to work with public-keys because you have to commit the key every time you want to push, pull or other communications with the git repository.

If you have a lot of git repositories for a project you have to change to the first directory, make a git pull, commit your password for the public key and go to the next directory. For a lot of directories it is very bad style.

This is were ssh-agent comes to the spot. I start the ssh-agent and commit my password for the public key once with ssh-add. After that you can work with all git repositories were you have the same public key committed. The idea of the ssh-agent is to start it once and then you have to put some environment variables into all your shell where you are working. That's not very nice for me so I wrote a zsh-function for that case. Here you can see the function:

 1:  function ssha {
 2:    if [ $# -ne 1 ]; then
 3:      echo "usage: $0 [start|stop]"
 4:      return 1
 5:    fi
 6:    case "$1" in
 7:      start)
 8:        if [ -n "$SSH_AGENT_PID" ]; then
 9:          echo "ssh-agent already running"
10:          return 1
11:        fi
12:        /usr/bin/ssh-agent > /tmp/ssh-agent-pids
13:        . /tmp/ssh-agent-pids > /dev/null
14:        /usr/bin/ssh-add
15:        ;;
16:      stop)
17:        if [ -z "$SSH_AGENT_PID" ]; then
18:          echo "ssh-agent not running"
19:          return 1
20:        fi
21:        /usr/bin/ssh-agent -k > /tmp/ssh-agent-pids
22:        . /tmp/ssh-agent-pids > /dev/null
23:        ;;
24:      *)
25:        echo "usage: $0 [start|stop]"
26:        return 1
27:        ;;
28:    esac
29:  }

You can start and stop the ssh-agent with the same function. If you are working with some git repositories you could start it with ssha start. Then you have to give your password for the public key and you can work in the same shell. After finishing some work with that git repositories you could stop the server with ssha stop.