<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://www.skepticats.com/LnBlog/themes/default/styles/rss.css" ?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<link>http://linlog.skepticats.com/feeds/PowerShell_news.xml</link>
<title>LinLog</title>
<description>Linux, Programming, and Computing in General</description>
<generator>LnBlog 1.0.0</generator>
<item>
<title>Command-line shortcuts         </title>
<link>http://linlog.skepticats.com/entries/2011/01/Command-line_shortcuts.php</link>
<description>
&lt;p&gt;I came across an interesting little program the other day.  It's called &lt;a href=&quot;http://code.google.com/p/go-tool/&quot;&gt;Go&lt;/a&gt;.  It's a Python script for quickly navigating directories via what are essentially command-line shortcuts.  I discovered it while perusing the settings in my Komodo Edit preferences - it was mentioned in the settings for the Fast Open extension, which I believe is included by default as of Komodo 5.1.&lt;br /&gt;&lt;img alt=&quot;komodo-fast-open.png&quot; title=&quot;komodo-fast-open.png&quot; src=&quot;http://linlog.skepticats.com/entries/2011/01/21_2109/komodo-fast-open.png&quot; /&gt;&lt;br /&gt;The beautiful thing about Go is how simple it is.  You run a simple command to set an alias and from there on out, you can just type &lt;code&gt;go alias&lt;/code&gt; and it will change you to that directory.  You can also add paths after the alias, such as &lt;code&gt;go alias/dir1/dir2&lt;/code&gt; to switch to a subdirectory of the alias.  Great for switching between deep hierarchies, like how Windows programs like to bury things three levels under your &amp;quot;Documents&amp;quot; directory.&lt;/p&gt;&lt;p&gt;However, as I played around with Go, I did come across a few annoyances.  The biggest one, or course, was that it didn't work under Powershell.  The go.bat wrapper script would run...and do nothing.  The current directory stayed the same.  Turns out this was because go uses a driver-based system for changing directory which is based on your current shell.  The Windows driver was using batch file syntax and running cmd.exe.  Powershell does this in a new process, so naturally the current directory wasn't changing.&lt;/p&gt;&lt;p&gt;So, in the spirit of open-source, I decided to fix that problem.  And while I was at it, I fixed a couple of other things and implemented some of the &lt;a href=&quot;http://code.google.com/p/go-tool/issues/detail?id=5&quot;&gt;feature&lt;/a&gt; &lt;a href=&quot;http://code.google.com/p/go-tool/issues/detail?id=6&quot;&gt;requests&lt;/a&gt; &lt;a href=&quot;http://code.google.com/p/go-tool/issues/detail?id=10&quot;&gt;posted&lt;/a&gt; on the Google Code issue tracker.  Here's the quick list:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Added support for Powershell.&lt;/li&gt;&lt;li&gt; Added built-in shortcut &amp;quot;-&amp;quot; pointing to the OLDPWD environment variable.  On Windows, Go handles setting this variable (on UNIX, &amp;quot;cd&amp;quot; takes care of that).&lt;/li&gt;&lt;li&gt; When invoked without any argument, change to home directory.&lt;/li&gt;&lt;li&gt; Resolve unique prefixes of shortcut, e.g &amp;quot;pr&amp;quot; resolves to &amp;quot;projects&amp;quot; if there's no other shortcut starting with &amp;quot;pr&amp;quot;.&lt;/li&gt;&lt;li&gt; Made -o option work without having the win32api bindings installed.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Below are a patch file for the official Go 1.2.1 release (apply with &lt;code&gt;patch -p2 &amp;lt; go-posh.patch&lt;/code&gt;) as well as a fully patched setup archive for those who just want to get up and running.  Note that, to enable Powershell support, prior to running the Go setup, you'll need to set the SHELL environment variable so that Go knows to use Powershell.  You can do this by adding &lt;code&gt;$env:SHELL = &amp;quot;powershell&amp;quot;&lt;/code&gt; to your Powershell profile script.&lt;/p&gt;&lt;p&gt;Patch file: &lt;a href=&quot;http://linlog.skepticats.com/entries/2011/01/21_2109/go-posh-1.2.1.patch&quot;&gt;go-posh-1.2.1.patch&lt;/a&gt;&lt;br /&gt;Full Go archive: &lt;a href=&quot;http://linlog.skepticats.com/entries/2011/01/21_2109/go-posh-1.2.1.zip&quot;&gt;go-posh-1.2.1.zip&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; Fixed support for &amp;quot;-&amp;quot; so that it &lt;em&gt;actually&lt;/em&gt; works like it does in UNIX.&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<comments>http://linlog.skepticats.com/entries/2011/01/21_2109/comments/</comments>
<guid>http://linlog.skepticats.com/entries/2011/01/21_2109/</guid>
</item>
<item>
<title>Powershell is not BASH and SVN pain </title>
<link>http://linlog.skepticats.com/entries/2010/12/Powershell_is_not_BASH_and_SVN_pain.php</link>
<description>
&lt;p&gt;Note to self: just because Powershell defines aliases that mimic many of the standard UNIX commands does not mean they function the same way.&lt;/p&gt;&lt;p&gt;Last night, I was trying to migrate my company's Subversion repository to Mercurial - not for production use (yet), just as an experiment.  After eventually getting the latest Mercurial installed on the Ubuntu 8.04 VM that hosts our Subversion repository, I tried running &lt;code&gt;hg convert -s svn /path/to/svn/repo /path/to/hg/repo&lt;/code&gt;.  As expected, the conversion process took some time, but chugged along nicely...for a while.  Eventually, it hit an error and came back with:&lt;br /&gt;&lt;code&gt;svn: In file '/build/buildd/subversion-1.6.9dfsg/subversion/libsvn_ra/ra_loader.c' line 595: assertion failed (*path != '/')&lt;/code&gt;&lt;/p&gt;&lt;p&gt;I Googled around a bit, but still have no idea what that error message means or how to fix it.  My best guess is that something is borked in our repo - not broken enough to break SVN, but maybeSo I tried a different tack - take the repository dump I had, import it into a fresh repository, and try again.  That didn't go so well....&lt;/p&gt;&lt;p&gt;Since the SVN VM has a very small drive, I decided to load the dumpfile on my local Windows box.  As you may know, &lt;code&gt;svnadmin load&lt;/code&gt; reads streams, so you have to either pipe the dump file in or redirect standard input.  Well, my first instinct was to do something like this:&lt;br /&gt;&lt;code&gt;svnadmin load newrepos &amp;lt; dumpfile.repo&lt;/code&gt;&lt;br /&gt;One problem with that: the &amp;quot;&amp;lt;&amp;quot; character that you normally use for redirecting STDIN is reserved in Powershell.  Drat!  So I figured I'd just use a pipe instead:&lt;br /&gt;&lt;code&gt;cat dumpfile.repo | svnadmin load newrepos&lt;/code&gt;&lt;br /&gt;So I ran that and waited.  And shortly after I started waiting, I noticed my system slowing down.  And then things started grinding to a halt - it was just &lt;em&gt;barely&lt;/em&gt; responding.  When I finally managed to get resmon up, I noticed that Powershell was eating nearly &lt;em&gt;all&lt;/em&gt; of my system's RAM!  And the command still hadn't produced a single line of output!&lt;/p&gt;&lt;p&gt;I'm not sure exactly what Powershell was doing, but it must have something to do with the Get-Content commandlet (for which &amp;quot;cat&amp;quot; is an alias) not liking the 1.4 GB dump file.  Why it would use up more than twice the size of the file in memory, I'm not sure.  &lt;/p&gt;&lt;p&gt;Anyway, I just switched to cmd.exe and did the input redirection method, which didn't eat huge amounts of memory.  However, it didn't work either.  The import died shortly after starting with an error about a bad transaction.  Looks like the gods of revision control are not smiling on me today.&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<comments>http://linlog.skepticats.com/entries/2010/12/22_1148/comments/</comments>
<guid>http://linlog.skepticats.com/entries/2010/12/22_1148/</guid>
</item>
<item>
<title>Fixing MediaMonkey playlists in RockBox  </title>
<link>http://linlog.skepticats.com/entries/2010/11/Fixing_MediaMonkey_playlists_in_RockBox.php</link>
<description>
&lt;p&gt;Yesterday I tried creating a playlist in MediaMonkey and synchronizing it with my Sansa e280 running RockBox.  I never really bothered with trying to sync playlists to my MP3 player before, because syncing, well, anything that's not an iPod using third-party software is a little iffy.  Needless to say, my fears were well founded.&lt;/p&gt;&lt;p&gt;While MediaMonkey's syncing feature is nice, I ran into several problems.  First, and most obvious, MediaMonkey didn't like the layout of my media directory.  You see, I have a main &amp;quot;Music&amp;quot; folder which contains a bunch of artist and album sub-folders, but also a bunch of miscellaneous MP3s at the top-level.  MediaMonkey didn't see those MP3s for some reason.  After the sync, they just weren't there - I had to copy them over manually.&lt;/p&gt;&lt;p&gt;My other problem was a combination of the playlists themselves, how RockBox on the Sansa works, and where I'm putting my music on the Sansa.  A couple of weeks ago, I &amp;quot;upgraded&amp;quot; my Sansa by buying a 16GB microSDHC card for it to complement the 8GB of internal flash storage.  This resulted in a change of organization - I now keep all my actual music on the microSD card and put podcasts and other spoken material on the internal storage.  Turns out that this messes with MediaMonkey's assumptions about playlists.&lt;/p&gt;&lt;p&gt;There are several issues here.  The first is that when MediaMonkey syncs to the microSD card, it sees it as a separate device and creates the playlists accordingly.  The result is that the playlists use absolute paths &lt;em&gt;within the microSD card&lt;/em&gt;.  However, the &lt;em&gt;real&lt;/em&gt; absolute path for files on the microSD card starts with the device path, i.e. &amp;lt;microSD1&amp;gt;.  So, basically, the paths in the playlist are wrong for RockBox.&lt;/p&gt;&lt;p&gt;The second issue is that the playlists get synced onto the microSD card.  This isn't really a problem, just now what I want.  I want the files synced to the main RockBox playlist folder on the Sansa's internal storage.&lt;/p&gt;&lt;p&gt;The third issue was with those assorted MP3s in my root &amp;quot;Music&amp;quot; directory.  Even though I set the sync path to &amp;lt;Path:2&amp;gt; in MediaMonkey's sync configuration, which should mirror the directory structure on my hard drive, when I ran the sync, the assorted files on my playlist got copied into a &amp;quot;Music&amp;quot; folder on the microSD card.  I'm not sure why.  But as long as that's the case, I decided to &amp;quot;solve&amp;quot; that problem by just moving the rest of the assorted files there too.  They weren't being synced anyway, so why not.&lt;/p&gt;&lt;p&gt;I decided to solve the playlist path and location problems with a simple Powershell script.  You can &lt;a href=&quot;http://linlog.skepticats.com/entries/2010/11/07_0041/fix-playlists.ps1&quot;&gt;download a copy here&lt;/a&gt;.  It simply reads your playlists, adjusts the paths, and moves them to the main device storage.  The code is below:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$source = &amp;quot;MUSICSD&amp;quot;&lt;br /&gt;$device = &amp;quot;Sansa e280&amp;quot;&lt;br /&gt;$listDir = &amp;quot;Playlists&amp;quot;&lt;/p&gt;&lt;p&gt;function findDriveByLabel {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$drives = [System.Io.DriveInfo]::GetDrives()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach ($drv in $drives) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ($args[0] -eq $drv.VolumeLabel) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $drv.RootDirectory&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;$sd = findDriveByLabel $source&lt;br /&gt;$dev = findDriveByLabel $device&lt;br /&gt;$sdDir = [System.Io.Path]::Combine($sd, $listDir)&lt;br /&gt;$devDir = [System.Io.Path]::Combine($dev, $listDir)&lt;/p&gt;&lt;p&gt;$lists = ls $sdDir&lt;/p&gt;&lt;p&gt;foreach ($lst in $lists) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$outFile = [System.Io.Path]::Combine($devDir, $lst.Name)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$outFile&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Get-Content $lst.FullName | ForEach-Object {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;/&amp;lt;microSD1&amp;gt;&amp;quot; + $_.Replace(&amp;quot;\&amp;quot;, &amp;quot;/&amp;quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;} | Out-File -Encoding utf8 -Width 1000 $outFile&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;rm $lst.FullName&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;$remLists = ls $sdDir&lt;br /&gt;if ($remLists -eq $Null) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;rmdir $sdDir&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;So far, this part is working fine.  I'm still not 100% happy with the sync experience, though.  The missing files is the part that really bugs me.  I'll have to do a little experimenting at some point and see if I can make it work.  Only problem is that it takes a while to write 16GB of data to the device....&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<comments>http://linlog.skepticats.com/entries/2010/11/07_0041/comments/</comments>
<guid>http://linlog.skepticats.com/entries/2010/11/07_0041/</guid>
</item>
<item>
<title>Putty alias </title>
<link>http://linlog.skepticats.com/entries/2010/08/Putty_alias.php</link>
<description>
&lt;p&gt;Here's a quick code post from my Powershell profile.  I keep copying this around every time I set up a new system, so maybe it will be useful to others.  And to me, since I can copy it off the web in the future rather than having to dig it up or recreate it.&lt;/p&gt;&lt;p&gt;Being an old-school UNIX guy, I get used to just typing &lt;code&gt;ssh hostname&lt;/code&gt; to access my servers.  So the Putty syntax of loading a profile annoys me.  To that end, I wrote a few little functions to add to my Powershell $profile to address this.  They just let me load a session by typing the familiar commands and don't require me to change syntax when using a profile versus connecting directly to a hostname.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;br /&gt;# Suppress the assembly loading output&lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName(&amp;quot;System.Web&amp;quot;) | Out-Null&lt;/p&gt;&lt;p&gt;function _puttyHasProfile {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$profile_name = $args[0].ToLower()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$profiles = Get-ChildItem HKCU:\Software\SimonTatham\PuTTY\Sessions\&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach ($p in $profiles) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$name = [System.IO.Path]::GetFileName($p.Name)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# Putty stores spaces and other special characters URL encoded.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$name = [System.Web.HttpUtility]::UrlDecode($name).ToLower()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ($name -eq $profile_name) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;function ssh {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$profile_name = $args[0]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_puttyHasProfile($profile_name)) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;putty -load $profile_name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;putty $args&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;function sftp {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$profile_name = $args[0]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_puttyHasProfile($profile_name)) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;psftp -load $profile_name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;psftp $args&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<comments>http://linlog.skepticats.com/entries/2010/08/31_0931/comments/</comments>
<guid>http://linlog.skepticats.com/entries/2010/08/31_0931/</guid>
</item>
<item>
<title>PowerShell highlighting in Vim  </title>
<link>http://linlog.skepticats.com/entries/2009/01/PowerShell_highlighting_in_Vim.php</link>
<description>
&lt;p&gt;Well, I feel stupid.  I just finally got syntax highlighting for PowerShell to work in Vim.  I did a little Googling and found my solution in the PDF document linked form &lt;a href=&quot;http://port25.technet.com/archive/2008/05/29/technical-analysis-vim-powershell-and-signed-code.aspx&quot;&gt;this article&lt;/a&gt;.  Why you need an 8 page PDF to explain this is a completely different issue.&lt;/p&gt;&lt;p&gt;Turns out I was just missing some lines in my filetype.vim file.  I already had the &lt;a href=&quot;http://www.vim.org/scripts/script.php?script_id=1327&quot;&gt;syntax&lt;/a&gt;, &lt;a href=&quot;http://www.vim.org/scripts/script.php?script_id=1815&quot;&gt;indent&lt;/a&gt;, and &lt;a href=&quot;http://www.vim.org/scripts/script.php?script_id=1816&quot;&gt;file type&lt;/a&gt; plugins, I just didn't think to add the code to activate them (for some reason I thought that stuff was loaded dynamically).  However, page 6 of that PDF gave the answer:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;quot; Powershell &lt;br /&gt;au BufNewFile,BufRead *.ps1,*.psc1    setf ps1 &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I just added those lines to my filetype.vim, below the corresponding entries for Povray files, and voilà!  Syntax highlighting now works.&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<slash:comments>2</slash:comments>
<comments>http://linlog.skepticats.com/entries/2009/01/22_1014/comments/</comments>
<wfw:commentRss>http://linlog.skepticats.com/entries/2009/01/22_1014/comments/comments.xml</wfw:commentRss>
<guid>http://linlog.skepticats.com/entries/2009/01/22_1014/</guid>
</item>
</channel>
</rss>
