それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

Windowsのホームディレクトリに出てくる、dotfiles を非表示にする。

windows のユーザーディレクトリにdotfiles があふれる。。

cygwinとかmsys 使ってたり、UNIXのコマンドを使うとドットファイルがあふれる。

これが美しくないのよ。ていうか邪魔

シンプルな解決策

attrib -h .bashrc

attribコマンドでファイルの属性を、「非表示」にしてあげれば、解決する。

でも、なんども非表示するのもめんどくさい。

ドットファイルをまとめて非表示にするプログラムがあればいいと思うの。

さらに、そのプログラムを定期的にattrib を実行すればいいと思うの。

フォルダ監視して、attrib を実行しておけば、ずっと見えないと思うんだよね。

非表示にするソースをぱぱっと書いた

#!/usr/bin/env ruby
#ドットから始まるファイルに隠しファイル属性を付加する
require 'rubygems'
require 'win32/file'

home = ENV["HOME"] 
home = `cygpath -w #{home}`.strip if RUBY_PLATFORM =~ /cygwin/
dotfiles = Dir.open(home).grep /^\.[^\.]+/
dotfiles + ["Downloads","Contacts","Searches"] + %w/Favorites Downloads Videos Music Contacts/
dotfiles.map!{|e| File.expand_path e, home }
#puts dotfiles
dotfiles.select{|e| true unless File.hidden? e }.each{|e| File.open(e){|f|f.hidden=true}}

でもrubyだとインストール面倒

rubywin32-fileを使えば解決するんだけどさ、コマンド登録面倒じゃないか。

スタートアップに登録したり、フォルダ監視に登録したり、サービスに登録するのも面倒じゃないか。

Win32 api で書けばいいよね。

windowだし、C/C++で書いておけば、ずっと使えると思うの。ruby のバージョンアップとか文字コードだとか、rubyのgemだとかそういうものに左右されない.

やっぱりwindows使うなら win32で書いておくのが鉄板だとおもうの。

dotfileをけす。

# include <windows.h>
//# include <stdio.h>


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;
    DWORD attrs;
    

    char* target_name = ".*";  
    char* target_dir;
    char* target;
    char* full_path;
    char buff[1024];
    
    GetEnvironmentVariable("USERPROFILE", buff, 1024);
    target_dir = (char *) malloc( sizeof(char) * lstrlen(buff) );
    lstrcpy(target_dir,buff);
    
    //文字列コピー sprintfのほうが楽かも・・・
    lstrcpy(buff, target_dir);
    lstrcat(buff, "\\");
    lstrcat(buff, target_name);
    target = (char *) malloc( sizeof(char) * lstrlen(buff) );
    lstrcpy(target,buff);

    //printf("target file is \"%s\".\n", target );
    hFind = FindFirstFile( target,&FindFileData);
    if ( hFind == INVALID_HANDLE_VALUE)
    {
        //printf("Invalid file handle: %d\n", GetLastError() );
        return 1;
    }
    
    do{
        if (lstrcmp(FindFileData.cFileName,".") == 0){
            continue;
        }
        if (lstrcmp(FindFileData.cFileName,"..") == 0){
            continue;
        }
        lstrcpy(buff, target_dir);
        lstrcat(buff, "\\");
        lstrcat(buff,FindFileData.cFileName );
        full_path = (char *) malloc( sizeof(char) * lstrlen(buff)+1024);
        lstrcpy(full_path,buff);
        

        SetFileAttributes(full_path, FILE_ATTRIBUTE_HIDDEN);
        attrs = GetFileAttributes(full_path);
        //printf("%s => 0x%04x\n",full_path, attrs);
        
    }while( FindNextFile( hFind,&FindFileData));
    
    FindClose(hFind);
    
    free(target_dir);
    free(target);
    free(full_path);
    
    return 0;
}

cygwinとかのgccコンパイル

i686-pc-mingw32-gcc hide-dots.c -o hide-dot-files -mwindows

これですっきりするよね。あとはスタートアップとかに仕込んでおけば結構楽になるわ

参考資料

Windows7:attribコマンドの使い方(属性を表示/設定/解除する)- 教えて!HELPDESK

https://msdn.microsoft.com/ja-jp/library/windows/desktop/aa365535(v=vs.85).aspx

brew でMacAppStoreを管理するコマンドmas-cliをインストール

MacAppStore のアプリをコマンドから

若者のMacAppStore離れが深刻ですが。MacAppstoreはアレはアレで便利には使えるものです。

Mas = Mac App Storeをコマンドからつかう

https://github.com/argon/mas を使うとコマンドから管理できるということなのでヤってみた。

インストール

brew でぱぱっと github から持ってくる。

takuya@~$ brew install argon/mas/mas
==> Tapping argon/mas
Cloning into '/usr/local/Library/Taps/argon/homebrew-mas'...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
Tapped 1 formula (25 files, 16.7K)
==> Installing mas from argon/mas
==> Downloading https://github.com/argon/mas/releases/download/v1.1.0/mas-cli.zip
==> Downloading from https://github-cloud.s3.amazonaws.com/releases/40092232/3170f432-d2be-11e5-999e-161b8e383e09.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credent
######################################################################## 100.0%^[
🍺  /usr/local/Cellar/mas/1.1.0: 2 files, 4.2M, built in 8 seconds

使い方の流れ

mas search Xcode  ## idを検索
mas install 497799835 ## idを指定

mas search で id を探す、mas install ID でインストール

インストール済み一覧を出す

takuya@~$ mas list
539883307 LINE
894760156 Desktop Clock free
409183694 Keynote
946680495 MARKETSPEED
417375580 BetterSnapTool
409183694 Keynote
428834068 YoruFukurou
421358730 MenuTab for Facebook
409789998 Twitter
408981381 iPhoto
425955336 Skitch
411678673 SourceTree
467939042 Growl
451444120 Memory Clean
586862299 Duplicate Cleaner For iPhoto
497799835 Xcode
412485838 Witch
409201541 Pages
409203825 Numbers
403388562 Transmit
408981434 iMovie
415181149 CalendarFree
715768417 Microsoft Remote Desktop
411213048 LadioCast
803453959 Slack
409203825 Numbers
449589707 Dash

help でサブコマンドが出てくる

takuya@~$ mas help
Available commands:

   account    Prints the primary account Apple ID
   help       Display general or command-specific help
   install    Install from the Mac App Store
   list       Lists apps from the Mac App Store which are currently installed
   outdated   Lists pending updates from the Mac App Store
   signin     Sign in to the Mac App Store
   signout    Sign out of the Mac App Store
   upgrade    Performs all pending updates from the Mac App Store
   version    Print version number

outdated 更新してないものを見つける

takuya@~$ mas outdated
539883307 LINE (4.4.1)

install は ID 指定

takuya@~$ mas install 539883307
==> Downloading LINE
==> Installed LINE

install 実行するとMacAppStore でログインダイアログがでてログインするとインストール開始

インストール済を管理するには便利そう

購入したけど使ってないものや、新規で購入ってのは難しそうですね。

参考資料

mas-cli: MacでApp Storeのアプリをコマンドラインからインストールする

2018-08-16

追記修正

grep で空行を捨てる。コメント行を捨てる。

grep で空行を消す。

/usr/bin/grep -v '^$'

簡単ですね。

  • 正規表現 ^$ で空行にマッチ
  • オプション -v でマッチした以外を表示

ついでにコメント行も捨てる

/usr/bin/grep -v '^$' | /usr/bin/grep -v '^#'
  • 正規表現 ^# で行頭のコメント
  • オプション -v でマッチした以外を表示
  • パイプでつなぐ

関連資料

http://takuya-1st.hatenablog.jp/entry/20100312/1268384541

Bash Completion for Mac OS X tmutil command

bash completion for tmutil

tmutil commands は OSX TimeMachine の管理用コマンド

gist.github.com

example

takuya@~$ tmutil listbackups
addexclusion       compare            disable            enablelocal        latestbackup       removedestination  setdestination     stopbackup         version
associatedisk      delete             disablelocal       inheritbackup      listbackups        removeexclusion    snapshot           uniquesize
calculatedrift     destinationinfo    enable             isexcluded         machinedirectory   restore            startbackup        verifychecksums

takuya@~$ tmutil latestbackup