<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Martin Ström &#187; bash</title>
	<atom:link href="http://my-domain.se/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://my-domain.se</link>
	<description></description>
	<lastBuildDate>Wed, 11 Jan 2012 11:04:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Screencapture in Mac OS X from a SSH session or launchd jobs</title>
		<link>http://my-domain.se/screencapture-in-mac-os-x-from-a-ssh-session-or-launchd-jobs/</link>
		<comments>http://my-domain.se/screencapture-in-mac-os-x-from-a-ssh-session-or-launchd-jobs/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 22:47:56 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://my-domain.se/?p=295</guid>
		<description><![CDATA[If you&#8217;d ever need to use the screencapture command from a scheduled job (like launchd in OS X) or from a SSH session, you might find out that it doesn&#8217;t allow you to do that since you&#8217;re not the logged in user. To work around that, run the scheduled jobs as root and exec screencapture [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;d ever need to use the <code>screencapture</code> command from a scheduled job (like launchd in OS X) or from a SSH session, you might find out that it doesn&#8217;t allow you to do that since you&#8217;re not the logged in user.</p>

<p>To work around that, run the scheduled jobs as root and exec <code>screencapture</code> like this instead:</p>

<script src="http://gist.github.com/323256.js?file=screenshot.sh"></script>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Terminal Setup for Rails Development</title>
		<link>http://my-domain.se/my-terminal-setup-for-rails-development/</link>
		<comments>http://my-domain.se/my-terminal-setup-for-rails-development/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 09:15:27 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/?p=117</guid>
		<description><![CDATA[I&#8217;m quite happy with my Terminal.app setup right now for the Rails projects I&#8217;m working on and wanted to share the bits and pieces I use. First, I found a SIMB plugin for Terminal that&#8217;ll show the tab&#8217;s title in the tab instead of the running process. I use the plugin with a simple title [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m quite happy with my Terminal.app setup right now for the Rails projects I&#8217;m working on and wanted to share the bits and pieces I use.</p>

<p>First, I found a <a href="http://flickr.com/photos/djgraphite/2280004671/">SIMB plugin for Terminal</a> that&#8217;ll show the tab&#8217;s title in the tab instead of the running process. I use the plugin with a simple <code>title</code> helper in my <code>.bash_profile</code> to set the title simply.</p>

<pre><code>function title () {
  unset PROMPT_COMMAND # more on this later
  echo___ -ne "\e]0;$1\a"
}

# Usage:
# title 'my title'
</code></pre>

<p>Second, I use a technique I saw on <a href="http://pseudogreen.org/blog/set_tab_names_in_leopard_terminal.html">how to automatically set the title to display the current working directory as title</a>, but since I use the plugin and helper function above, I could simplify the <code>PROMPT_COMMAND</code> a bit:</p>

<pre><code>function set_window_and_tab_title {
  local title="$1"
  [[ -z "$title" ]] &amp;&amp; title="root"
  echo___ -ne "\e]0;${title}\a"
}

PROMPT_COMMAND='set_window_and_tab_title "${PWD##*/}"'
</code></pre>

<p>That&#8217;s why I unset <code>PROMPT_COMMAND</code> in my <code>title</code> function, so it won&#8217;t auto update when I choose to set it manually using the <code>title</code> function.</p>

<p>The last piece is an updated version of my old <a href="http://burnfield.com/martin/2007/07/19/applescript-to-open-iterm-tabs-for-rails-development/">Rails Term-script for iTerm</a> which has been updated (and improved) for the Terminal in Mac OS X Leopard instead of iTerm.</p>

<p>It will open the tabs I usually use when doing Rails development and set the title of each tab using the above mentioned functions. You need to enter you projects root directory and the projects you want to have easy access to. I&#8217;ve added some comments to the AS code to help you out.</p>

<p><a href="http://burnfield.com/martin/wordpress/wp-content/uploads/RailsTerm.zip">Download a zipped version of the AppleScript</a>. Just drag the script to the Script Editor (/Applications/Utilities) to edit it.</p>

<p>All source code for these scripts can also be viewed on <a href="http://pastie.textmate.org/230228">Pastie</a>. Let me know if you have any improvements.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>./script/server with automatic port finder</title>
		<link>http://my-domain.se/scriptserver-with-automatic-port-finder/</link>
		<comments>http://my-domain.se/scriptserver-with-automatic-port-finder/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 21:20:15 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/?p=116</guid>
		<description><![CDATA[This is the script I&#8217;m using when I start my local Rails development server. It will automatically detect the next available port starting at the default port 3000 so I can have multiple servers running without remembering what ports that are already busy. #!/usr/bin/env ruby DEFAULT_PORT = 3000 puts (`ps aux &#124; grep [r]uby &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>This is the script I&#8217;m using when I start my local Rails development server. It will automatically detect the next available port starting at the default port 3000 so I can have multiple servers running without remembering what ports that are already busy.</p>

<pre><code>#!/usr/bin/env ruby

DEFAULT_PORT = 3000

puts (`ps aux | grep [r]uby | grep script/server`.split("\n").map { |l|
  server = l.split(/\s+/)[11..-1]
  (port = server.index('-p')) ? server[port.next].to_i : DEFAULT_PORT
}.max || DEFAULT_PORT - 1).next
</code></pre>

<p>I aliased it to <code>ss</code> in <code>.bash_profile</code> like this:</p>

<pre><code>alias ss='./script/server -p `~/bin/available_rails_port`'
</code></pre>

<p>(Btw, Happy 2008! I haven&#8217;t updated this site for a while)</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Autonamed dump/temp folder</title>
		<link>http://my-domain.se/autonamed-dump-folder/</link>
		<comments>http://my-domain.se/autonamed-dump-folder/#comments</comments>
		<pubDate>Thu, 06 Jul 2006 22:04:23 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2006/07/07/autonamed-dump-folder/</guid>
		<description><![CDATA[To keep my desktop nice and clean I have a folder called &#8220;Dump&#8221; where I put temporary stuff like apps I want to try, PDF:s to read later that day or files I&#8217;m currently working with. But sometimes I forget to look inside that folder to find out what&#8217;s there so I wrote this Folder [...]]]></description>
			<content:encoded><![CDATA[<p>To keep my desktop nice and clean I have a folder called &#8220;Dump&#8221; where I put temporary stuff like apps I want to try, PDF:s to read later that day or files I&#8217;m currently working with. But sometimes I forget to look inside that folder to find out what&#8217;s there so I wrote this <a href="http://www.apple.com/applescript/folderactions">Folder Action</a> to let the folders name reflect the number of containing files/folders. (I know I could just enabled &#8220;Show item info&#8221; from Finders &#8220;View Options&#8221; but I don&#8217;t want to see all info for my hard drives and iPod)</p>

<p><img src="http://my-domain.se/wordpress/wp-content/uploads/2006/07/autonamed-dump-folder.png" alt="autonamed-dump-folder.png" class="centered" /></p>

<p>Just create a folder on your desktop, name it something like &#8220;Dump (temp)&#8221; and attach this Folder Action to it (Folder Actions need to be located in <code>~/Library/Scripts/Folder Actions</code>).</p>

<pre><code>-- Set item count as folder name.scpt
on adding folder items to this_folder
    my update_name(this_folder)
end adding folder items to

on removing folder items from this_folder
    my update_name(this_folder)
end removing folder items from

on update_name(this_folder)
    set this_name to POSIX path of this_folder
    set sh_script to do shell script "P=\"" &amp; (POSIX path of (path to me) as string) &amp; "\";echo ${P/%.scpt/.sh}"
    set new_name to do shell script "\"" &amp; sh_script &amp; "\" \"" &amp; this_name &amp; "\""
    tell application "Finder" to set name of this_folder to new_name
end update_name
</code></pre>

<p>The script needs a shell script to work (since I don&#8217;t like working with AppleScript that much). It should be named exacly as the AppleScript but with an <code>.sh</code> extension instead of <code>.scpt</code> and put in the same directory. Remember to make it executable (<code>chmod +x "Set item count as folder name.sh"</code>).</p>

<pre><code>#!/usr/bin/env bash
# Set item count as folder name.sh

# Since the folder has a custom icon and therefore a `Icon?` file I
# decrease the item count by 1. Bad solution but works for now.
NUM_ITEMS=`bc &lt;&lt;&lt; "$(ls "$1" | wc -l) - 1"`
if [[ $NUM_ITEMS == 0 ]]; then
    ITEMS="empty"
elif [[ $NUM_ITEMS == 1 ]]; then
    ITEMS="$NUM_ITEMS item"
else
    ITEMS="$NUM_ITEMS items"
fi
BASE=`ruby -e "puts %x(basename \"$1\").match(/(.+) \(/)"[1]`
echo "$BASE ($ITEMS)"
</code></pre>

<p>I first renamed the folder from the shell script but then Finder would visually move the folder one step down or left on the desktop for every update. Instead I just let the shell script generatr the new name and pass it back to the AppleScript that will rename the file as I want.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Terminal.app usage</title>
		<link>http://my-domain.se/terminalapp-usage/</link>
		<comments>http://my-domain.se/terminalapp-usage/#comments</comments>
		<pubDate>Fri, 07 Apr 2006 15:09:11 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/2006/04/07/terminalapp-usage/</guid>
		<description><![CDATA[The other day, Oskar Karlin asked me how and when I use the OS X Terminal app instead of e.g. the Finder. I&#8217;m not by any means a hard core command line guy but ther are often and often situations where the Terminal is faster or/and easier to use for the specific thing. To resize [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, <a href="http://oskarlin.com">Oskar Karlin</a> asked me how and when I use the OS X Terminal app instead of e.g. the Finder. I&#8217;m not by any means a hard core command line guy but ther are often and often situations where the Terminal is faster or/and easier to use for the specific thing.</p>

<ul>
<li><p>To resize all PNG-images in the current folder to 600px width
<code>find . -name "*.png" -type f -exec sips --resampleWidth 600 {} \;</code></p></li>
<li><p>To put in a &#8220;.thumbnail&#8221; in the file name
<code>for file in *.png; do mv $file ${file/.png/.thumbnail.png}; done</code></p></li>
<li><p>When I needed to know how many tracks we (<a href="http://pluxemburg.com">Pluxemburg</a>) sent to <a href="http://www.apple.com/itunes/">ITMS</a>
<code>find Music/iTunes\ Producer/Playlists -name metadata.xml -exec grep "&lt;track&gt;" {} \; | wc -l</code></p></li>
<li><p>Copy a file to our <a href="/">Burnfield</a> server  (instead of launching a FTP-client)
<code>scp myfile burnfield@bidwell.textdrive.com:</code></p></li>
<li><p>Basic, but to view the apache error log
<code>tail /var/log/httpd/error_log</code></p></li>
<li><p>To view the source of this site&#8217;s feed
<code>curl "http://burnfield.com/martin/feed" | head</code></p></li>
<li><p>And how <a href="http://feedburner.com">FeedBurner</a> gets it
<code>curl --user-agent FeedBurner "http://burnfield.com/martin/feed" | head</code></p></li>
</ul>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pluxemburg upload script</title>
		<link>http://my-domain.se/pluxemburg-upload/</link>
		<comments>http://my-domain.se/pluxemburg-upload/#comments</comments>
		<pubDate>Tue, 16 Aug 2005 23:44:33 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[pluxemburg]]></category>

		<guid isPermaLink="false">http://burnfield.com/martin/wordpress/?p=16</guid>
		<description><![CDATA[Today when working with the pluxemburg.com-site I got really tired of uploading everything with Transmit. Since our host doesn&#8217;t have support for rsync or something like that, I made this really easy bash-script that will upload everything that have been changed since last time the script was runned. cd ~/Projects/Pluxemburg/pluxemburg.com #local path to site root [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://my-domain.se/wordpress/wp-content/uploads/pluxemburg_uploader.png" alt="" class="centered" /></p>

<p>Today when working with the <a href="http://www.pluxemburg.com/">pluxemburg.com</a>-site I got really tired of uploading everything with <a href="http://www.panic.com/transmit/">Transmit</a>. Since our host doesn&#8217;t have support for rsync or something like that, I made this really easy bash-script that will upload everything that have been changed since last time the script was runned.</p>

<pre><code>cd ~/Projects/Pluxemburg/pluxemburg.com #local path to site root
find . -newer ./lastupload -exec open -a Transmit "{}" \;
touch ./lastupload
</code></pre>

<p>In Transmit, remember that both local and remote paths have been set, and &#8220;Use DockSend&#8221; enabled. I saved the script as an application using <a href="http://www.apple.com/macosx/features/automator/">Automator</a> (Automator &#8211;> Run Shell Script), and made an icon in 20 seconds.
Now I just run the app from QuickSilver or Finder and it uploads everything really fast and easy.</p>

<p><strong>Update</strong>: This is for OS X and only tested in 10.4 Tiger</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

