Archive

Archive for September, 2009

Using it’s all text on Mac OS X

September 15th, 2009 11 comments

Introduction

As a system administrator, I dislike to edit text in Firefox (or any other webbrowser), for example to write a new post on this blog, or edit some contents in drupal. This morning, I was looking for a Firefox extension allowing to use an external editor (in my case vim, for sure) to edit contents of textarea. This extension is pretty simple, you only need to configure which command to run to edit the file.

However there is a big trouble with Mac OS X, indeed, I was not able to find a command line to open a new terminal tab and lauching vim with the file to edit. Indeed, something like:


% open -a iTerm /usr/bin/vim

is working fine, however, it’s not possible to do something like:


% open -a iTerm /usr/bin/vim -- /tmp/file_to_edit

That’s very inconvenient, isn’t it! So, the only way I found to achieve that is to write an AppleScript to open a new iTerm, using vim profile (which runs vim as startup), and then open the file by sending text to vim from the AppleScript. But, once gain, I run out of luck. Indeed, the filename computed by it’s all text contains spaces, and vim expect escaped spaces. So, I look for a way to replace string in AppleScript, but… guess what? it’s seem very difficult (because I need to create another file..). So the only simple solution I found is to create a shell script that create a symbolic link in /tmp to the file to edit.. Here we go!

Configuration

iTerm
Open your bookmarks manager, and create a new bookmark like
that:

Image 8

Open a terminal, create the directory ~/bin, create the file
editfile with the following contents (replace bbonfils
with your login name):

#!/bin/zsh
 
extension=${1:e}
link="/tmp/firefox."$$".${extension}"
 
ln -s "$1" $link
 
/Users/bbonfils/bin/editfile.scpt $link

Create a new file named editfile.scpt with the following contents:

#!/usr/bin/osascript

on run argv
        tell application "iTerm"
                activate
                make new terminal
                tell the last terminal
                        launch session "vim"
                        tell the last session
                                write text "^[[:e " & item 1 of argv
                        end tell
                end tell
        end tell
end run

Ensure both are executable chmod +x, and then configure it’s all text
to use the first script to open file (/User/bbonfils/bin/editfile), and
now it should work!

The last word

Note I can’t remove the link in the script, since all of them are executed in background,
if you add a rm in the think, the link will be removed few seconds after you start vim,
so your textarea contents won’t be updated.

And yes, I know, it’s ugly, if you have a better way to achieve that, please post it in comments!

Categories: Misc Tags: ,

Networking, QoS and OpenSolaris

September 12th, 2009 No comments

OpenSolaris 200906 comes with some very interesting features about networking management. One is flowadm, allowing to manage network streams in a very simple and elegant way. For example, the next commands allow me to restrict the bandwith for my HTTP server.


flowadm add-flow -l bge0 -a transport=tcp,local_port=80 httpflow
flowadm set-flowprop -p maxbw=8 httpflow


wget -O /dev/null http://eva0/empty
2009-09-12 17:32:07 (971 KB/s) - « /dev/null »

As you can see it’s very simple! The following properties can be applied to a stream:

  • maxbw: Sets the full duplex bandwidth for the flow.
  • priority: Sets the relative priority for the flow.
  • cpus: Allocate packets of the flow to a processor set, for systems that have multiple
    processor sets. (this property is not yet available, maybe in 200911?)

References:

  • Configuring Virtual Networks
  • Configuring Resource Management on Data Links
  • Categories: OpenSolaris Tags: