プロキシ環境下のSSH設定
プロキシ環境下で外部にSSHを使いたいときは~/.ssh/configもしくは/etc/ssh/ssh_configにProxyCommandの設定を行いますが、Hostの書き方にハマったのでメモします。
Vagrantではゲストにlocalhost:2222でSSH接続します。外部接続はプロキシを使い、localhostに対してはプロキシを使わないという設定を行いたかったのですが、Hostのパターンに !localhost,* と書いても期待する動作にはなりませんでした。
最終的に以下の書き方で落ち着きました。
Host localhost ProxyCommand none Host 127.0.0.1 ProxyCommand none Host * ProxyCommand connect -H proxy.example.com:80 %h %p
なお、試したのは git for windows (git version 1.9.4.msysgit.0) に付属の ssh (OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007) です。
Windows 7に乗り換えたらコマンドライン・ランチャーは不要になりました
bluewindからCraftLaunchへの移行 を行ったばかりですが、OSをWindows XPからWindows 7に乗り換えたらコマンドライン・ランチャーは不要になりました。
Windows 7のスタートメニューにある「プログラムとファイルの検索」を使うと、bluewindやCraftLaunchのようにコマンドラインでアプリケーションを起動することができます。
しかし、そのままでは秀丸を起動するのに「秀丸」と入力しなければいけないので、非効率です。インクリメンタルサーチが使えても漢字で入力するのでは意味がありません。
そこで、CraftLaunchの設定ファイルをWindowsのショートカットに変換するスクリプトを作成しました。これで秀丸はWindowsキー + 「Hidemaru」の途中まで入力すれば起動できます。
Python for Windows Extensions を初めて使ってみたのですが、PythonからWSHが使えるのは便利ですね。
#! /usr/bin/env python # -*- coding: utf-8 -*- # # usage: craftLaunch2Shortcut.py # # インストール要件 : # # Python for Windows Extensions # http://starship.python.net/crew/mhammond/win32/ # # 参考 : # # WshShortcut オブジェクト # http://msdn.microsoft.com/ja-jp/library/cc364438.aspx # # ShellExecute 関数 # http://msdn.microsoft.com/ja-jp/library/cc422072.aspx # # ShowWindow Function (Windows) # http://msdn.microsoft.com/en-us/library/ms633548(v=vs.85).aspx import os import os.path import re import win32com.client shell = win32com.client.Dispatch('WScript.Shell') launcher_dir = os.path.join(shell.SpecialFolders("StartMenu"), "Programs", "QuickLaunch") if os.path.isdir(launcher_dir) != True: os.mkdir(launcher_dir) config_file = os.path.join(os.environ['APPDATA'], "CraftLaunch", "config.py") for line in open(config_file, 'r'): m = re.match(r" \( u\"(.*)\", *window\.command_ShellExecute\( " \ "None, u\"(.*)\", u\"(.*)\", u\"(.*)\", (.*) \) \), # (.*)", unicode(line, "utf-8")) if m != None: path_name = m.group(1).encode('cp932') target_path = m.group(2).encode('cp932') parameter = m.group(3).replace("\\\"", "\"").encode('cp932') working_directory = m.group(4).encode('cp932') showstate = m.group(5).encode('cp932') if showstate == "3": # SW_SHOWMAXIMIZED showstate = "3" elif showstate == "2" or showstate == "7": # SW_SHOWMINIMIZED or SW_SHOWMINNOACTIVE -> SW_SHOWMINNOACTIVE showstate = "7" else: # SW_SHOWMINIMIZED showstate = "1" description = m.group(6).encode('cp932') print path_name + '\t' + target_path + '\t' + parameter + '\t' \ + working_directory + '\t' + showstate + '\t' + description shortcut = shell.CreateShortCut(os.path.join(launcher_dir, path_name + ".lnk")) shortcut.Targetpath = target_path shortcut.Arguments = parameter shortcut.WindowStyle = showstate shortcut.Description = description shortcut.WorkingDirectory = working_directory shortcut.save()
情報のインプットについて整理してみる
今年の目標の一つに「インプットの質を高める」をあげたので、インプットについて整理してみる。
- けちらずに本を買う。必要な情報はすべてWebにあるんだろうけど、本のS/N比の高さをもっと評価すべき。
今年の目標
- 忙しいをいいわけにしない。優先順位付けができていないのと段取りの悪さを何とかする。
- アウトプットの量を増やす。ブログのエントリーが年に一件とは恥ずかしすぎる。質よりもまずは量。「MacBook Air 11インチ欲しい!」と書きこむだけで、応募完了するキャンペーンには必ず反応する。
- インプットの質を高める。そのインプットがアウトプットに役立つかを意識する。garbage in, garbage outだしね。
- 人の気持ちに鈍感なところがあるので、もう少し気配りができるようになる。
bluewindからCraftLaunchへの移行
コマンドライン・ランチャーとしてbluewindを愛用していましたが、CraftLaunchに移行することにしました。
bluewindに登録されたコマンドの数が多いので、bluewindの設定ファイルをCraftLaunch用に変換するツールをPythonで書いてみました。実はPythonを使うのはほぼ初めてなので、おまえのコードは汚いという突っ込みがありましたら教えて下さい。
#! /usr/bin/env python # -*- coding: utf-8 -*- # # usage: bluewind2CraftLaunch.py < %.wind # 参考 : # # ShellExecute 関数 # http://msdn.microsoft.com/ja-jp/library/cc422072.aspx # # ShowWindow Function (Windows) # http://msdn.microsoft.com/en-us/library/ms633548(v=vs.85).aspx import re import sys def getValue(list, name): for item in list: m = re.search("^" + name + "=(.*)", item) if m: return m.group(1) return None print ' window.launcher.command_list += [' for line in sys.stdin: list = unicode(line, "cp932").rstrip().split("\t") bw_keyword = list[0] bw_type = getValue(list[1:], "Type") bw_comment = getValue(list[1:], "Comment") bw_command = getValue(list[1:], "Command") bw_param = getValue(list[1:], "Param") bw_dir = getValue(list[1:], "Dir") bw_showstate = getValue(list[1:], "ShowState") if bw_type == "0": cl_command = bw_keyword.encode('cp932') cl_file = bw_command.replace("\\\\", "/").replace("\\s", " ").encode('cp932') if bw_param: cl_param = bw_param.replace("\\\\", "/").replace("\\s", " ").encode('cp932') else: cl_param = "" if bw_dir: cl_directory = bw_dir.replace("\\\\", "/").replace("\\s", " ").encode('cp932') else: cl_directory = "" if bw_showstate == "1": cl_swmode = 3 # SW_SHOWMAXIMIZED elif bw_showstate == "2": cl_swmode = 2 # SW_SHOWMAXIMIZED else: cl_swmode = 1 # SW_SHOWNORMAL if bw_comment: cl_comment = bw_comment.replace("\\\\", "/").replace("\\s", " ").encode('cp932') else: cl_comment = "" print ' ( u"{0}", window.command_ShellExecute( None, u"{1}", u"{2}", u"{3}", {4} ) ), # {5}'.format(cl_command, cl_file, cl_param, cl_directory, cl_swmode, cl_comment) print ' ]'
単独の代入、インクリメント演算子、デクリメント演算子はvoid文
PS > $a = 1 PS > $a 1 PS > $a++ PS > $a++ + 0 2 PS > [void]($a++ + 0) PS >
最後の例は、明示的に結果を破棄するために、void文にキャストしている。
エンコードを指定しないとファイル出力はUTF-16
PowerShellの文字列はUnicodeを使用するので、
date > date.txt
を実行すると、例えば、
2009年8月18日 9:43:06
という内容がdate.txtというファイルにUTF-16で保存される。
ここで、
date > date.txt
は、
Get-Date | Out-File -filePath date.txt
のシンタックスシュガーなので、Out-Fileのパラメータでエンコードを指定し、
Get-Date | Out-File -filePath date.txt -encoding Default
とすれば、システムのエンコード(日本語環境ではCP932)で保存される。