hogashi.*

日記から何から

VSCodeのUriでファイルシステム上のパスを見るときはpathよりfsPathがよさそう

 VSCode拡張機能を作ったりするとき、 vscode.Uriファイルシステム上のパスを見るには、 path よりも fsPath のほうが (OS に合わせたパスになるので) よさそう。
 Mac では値が変わらないので気づかなかったけど、 Windows ではこういう感じで値が違う。

path: '/c:/Users/azuma/Documents/ghq/test/vscode-copy-github-permalink'
fsPath: 'c:\\Users\\azuma\\Documents\\ghq\\test\\vscode-copy-github-permalink'

 vscode.Uri の型についているコメントを見ると説明されている *1https://github.com/microsoft/vscode/blob/58e7c7b8865e3c3ea77055461ffb5d656a7a46af/src/vscode-dts/vscode.d.ts#L1420-L1440
 UNIX 系?のファイルシステムでは、パスの区切りがスラッシュだけど、 Windows ではバックスラッシュで、 fsPath はそこを含めてプラットフォームに合わせたパスになっている、と書かれていそう。あと UNC paths というのは Windows ネットワークにおけるパスとしてそういう表記方法があるらしい。

* The string representing the corresponding file system path of this Uri.
*
* Will handle UNC paths and normalize windows drive letters to lower-case. Also
* uses the platform specific path separator.
*
* * Will *not* validate the path for invalid characters and semantics.
* * Will *not* look at the scheme of this Uri.
* * The resulting string shall *not* be used for display purposes but
* for disk operations, like `readFile` et al.
*
* The *difference* to the {@linkcode Uri.path path}-property is the use of the platform specific
* path separator and the handling of UNC paths. The sample below outlines the difference:
* ```ts
* const u = URI.parse('file://server/c$/folder/file.txt')
* u.authority === 'server'
* u.path === '/shares/c$/file.txt'
* u.fsPath === '\\server\c$\folder\file.txt'
* ```
https://github.com/microsoft/vscode/blob/58e7c7b8865e3c3ea77055461ffb5d656a7a46af/src/vscode-dts/vscode.d.ts#L1420-L1440
日記

 VSCode拡張機能で、開いているファイルに対応する GitHub 上での URL をコピーするというの *2 を作っている。不具合を issue *3 で教えてもらい、 Mac で直したら Windows で動かなくなっていて、 Windowsデバッグしたら pathfsPath の違いがあることに気づいた。
 直したあと issue 上で動かなくなったよって教えてもらったときには Mac でしか試してなくて、再現しなくてなんでだろ……と思ったまま 2ヶ月経っていたのだけど、他の人にもそういえばその後どう?ってコメントしてもらって、 Windows で再現手順をもらったところで、そういえば Windows で動かないってことがあるのかも、と気づけた。ファイルシステムのパスを扱うときは OS の違いも意識したい……。

Gitのサブコマンド眺めたりgit help help見たりした

 git help help を初めて見た。 #102: Do Developers Really Know How to Use Git Commands? A Large-scale Study Using Stack Overflow – Misreading Chat で Git のサブコマンドの話をしていて、 140個ある!って言っててマジか、と思って git help --all とかに辿り着いたりした。サブコマンドがジャンルごとに紹介されている。

$ git help --all --no-external-commands --no-alias | grep '^[^ ]'
See 'git help <command>' to read about a specific subcommand
Main Porcelain Commands
Ancillary Commands / Manipulators
Ancillary Commands / Interrogators
Interacting with Others
Low-level Commands / Manipulators
Low-level Commands / Interrogators
Low-level Commands / Syncing Repositories
Low-level Commands / Internal Helpers
User-facing repository, command and file interfaces
Developer-facing file formats, protocols and other interfaces

 あとそういえばと思って git help help 見たらもちろんあった。
git-scm.com
 よく見ると --man の他に --info とか --web とかがあることがわかっておもしろい。 Google Chrome など好きなブラウザのコマンドか実行ファイルへのパス*1を .gitconfig の web.browser に設定しておくとブラウザで HTML 形式のヘルプが見れる。例えば git help --web status を見るとfile:///opt/homebrew/Cellar/git/2.38.1/share/doc/git-doc/git-status.html が開かれていてそこにあるのか〜という感じ (ディレクトリを見るとたしかにたくさん入っている)。多分 git-scm.com で見れるものと内容は同じだと思う。

 全然関係ないけど、 git help --all --no-external-commands --no-alias (v2.38.1 時点) で見れるコマンドを全部 RegExp::Assemble *2 にかけるとこういう正規表現が得られる。見どころは c(at-file|he(ck(...|out(...|l(ean|i|one)|... あたりで、 check 系がいっぱいと、 cherry 系があるのと、 clean/cli/clone の cl 三兄弟がいるのと、その他 c 始まりがたくさんある。

$ rassemble $(git help --all --no-external-commands --no-alias | grep '^ ' | awk '{ print $1 }' | sort | tr '\n' ' ')
a(?:dd|m|nnotate|pply|rchi(?:mport|ve)|ttributes)|b(?:isect|lame|ranch|u(?:greport|ndle))|c(?:at-file|he(?:ck(?:-(?:attr|ignore|mailmap|ref-format)|out(?:-index)?)|rry(?:-pick)?)|itool|l(?:ean|i|one)|o(?:lumn|mmit(?:-(?:graph|tree))?|nfig|unt-objects)|redential(?:-(?:cach|stor)e)?|vs(?:(?:exportcommi|impor)t|server))|d(?:aemon|escribe|i(?:agnose|ff(?:-(?:files|index|tree)|tool)?))|f(?:ast-(?:ex|im)port|etch(?:-pack)?|ilter-branch|mt-merge-msg|or(?:-each-re(?:f|po)|mat-(?:(?:bundl|signatur)e|c(?:hunk|ommit-graph)|index|pa(?:ck|tch)))|sck)|g(?:c|et-tar-commit-id|it(?:k|web)|rep|ui)|h(?:ash-object|elp|ooks?|ttp-backend)|i(?:gnore|map-send|n(?:dex-pack|it|staweb|terpret-trailers))|l(?:og|s-(?:files|(?:remot|tre)e))|m(?:ai(?:l(?:info|map|split)|ntenance)|erge(?:-(?:(?:bas|(?:one-)?fil|tre)e|index)|tool)?|kt(?:ag|ree)|odules|ulti-pack-index|v)|n(?:ame-rev|otes)|p(?:4|a(?:ck-(?:objects|re(?:dundant|fs))|tch-id)|r(?:otocol-(?:c(?:apabilities|ommon)|http|pack|v2)|une(?:-packed)?)|u(?:ll|sh))|quiltimport|r(?:ange-diff|e(?:(?:ad-tre|bas|mot|rer)e|flog|p(?:ack|lace|ository-layout)|quest-pull|s(?:et|tore)|v(?:-(?:list|parse)|ert|isions))|m)|s(?:calar|end-(?:email|pack)|h(?:-(?:i18n|setup)|o(?:rtlog|w(?:-(?:branch|index|ref))?))|parse-checkout|t(?:a(?:sh|tus)|ripspace)|ubmodule|vn|witch|ymbolic-ref)|tag|u(?:npack-(?:file|objects)|pdate-(?:index|ref|server-info))|v(?:ar|er(?:ify-(?:commit|pack|tag)|sion))|w(?:hatchanged|(?:ork|rite-)tree)

 実際頭文字で数えると c 始まりが一番多いようでおもしろい。

$ git help --all --no-external-commands --no-alias | grep '^ ' | awk '{ print $1 }' | cut -c1 | sort | uniq -c | sort -nr
  25 c
  18 s
  17 r
  16 m
  16 f
  14 p
   8 d
   7 a
   6 i
   6 g
   5 v
   5 u
   5 h
   5 b
   4 l
   3 w
   2 n
   1 t
   1 q

 ちなみに正規表現Regexper で図にするとこうなった。長い。頭文字 c だけ抜粋したものを貼りつつ全部の図も details の中に入れておきます。

クリックして図の全体を見る (SVGです) Created with Snapaddmnnotatepplyrchimportvettributesbisectlameranchugreportndlecat-fileheck-attrignoremailmapref-formatout-indexrry-pickitoolleanioneolumnmmit-graphtreenfigunt-objectsredential-cachstorevsexportcommiimportserverdaemonescribeiagnoseff-filesindextreetoolfast-eximportetch-packilter-branchmt-merge-msgor-each-refpomat-bundlsignaturechunkommit-graphindexpacktchsckgcet-tar-commit-iditkwebrepuihash-objectelpooksttp-backendignoremap-sendndex-packitstawebterpret-trailerslogs-filesremottreemailinfomapsplitntenanceerge-basone-filtreeindextoolktagreeodulesulti-pack-indexvname-revotesp4ack-objectsredundantfstch-idrotocol-capabilitiesommonhttppackv2une-packedullshquiltimportrange-diffead-trebasmotrereflogpacklaceository-layoutquest-pullsettorev-listparseertisionsmscalarend-emailpackh-i18nsetuportlogw-branchindexrefparse-checkouttashtusripspaceubmodulevnwitchymbolic-reftagunpack-fileobjectspdate-indexrefserver-infovarerify-commitpacktagsionwhatchangedorkrite-tree

*1:Google Chrome の場所は特に Mac だとよくわからないけど Chrome Browser debug logs - Chrome Enterprise and Education Help とかを見るとわかる

*2:実際使ったのは itchyny/rassemble-go

CSSのcounters()で箇条書きの数字をカスタマイズできておもしろい

 CSS に counters() というのがあって、 1.1 とかをカスタマイズできておもしろい。 counters() - CSS&colon; Cascading Style Sheets | MDN
  というのをシンボルに使うことにして、繋ぎを にするとこうなる。

@counter-style kotonohanoniwa {
  system: fixed;
  symbols: 言 葉 庭;
  suffix: " ";
}

ol {
  counter-reset: kounter;
}
ol li {
  counter-increment: kounter;
  margin-left: 30px;
}
ol li::marker {
  content: counters(kounter, 'の', kotonohanoniwa) ") ";
}

 実際に ol で見るとこう。

  1. 1
    1. 1, 1
      1. 1, 1, 1
      2. 1, 1, 2
      3. 1, 1, 3
    2. 1, 2
      1. 1, 2, 1
      2. 1, 2, 2
      3. 1, 2, 3
    3. 1, 3
      1. 1, 3, 1
      2. 1, 3, 2
      3. 1, 3, 3
  2. 2
    1. 2, 1
      1. 2, 1, 1
      2. 2, 1, 2
      3. 2, 1, 3
    2. 2, 2
      1. 2, 2, 1
      2. 2, 2, 2
      3. 2, 2, 3
    3. 2, 3
      1. 2, 3, 1
      2. 2, 3, 2
      3. 2, 3, 3
  3. 3
    1. 3, 1
      1. 3, 1, 1
      2. 3, 1, 2
      3. 3, 1, 3
    2. 3, 2
      1. 3, 2, 1
      2. 3, 2, 2
      3. 3, 2, 3
    3. 3, 3
      1. 3, 3, 1
      2. 3, 3, 2
      3. 3, 3, 3

 数字は何個目の箇条かを書いただけで、 MDN の例に倣うとこれも counters() で出せるっぽい。というか今は marker の contents として counters してるというだけで、どこに出してもいいわけだから、なんかおもしろい使い方ができそう。

 追記) ブコメに書いてもらってて気づいたけど、 Safari だと @counter-style が未実装でただの数字に見える。 MDN とかをよく見ると Chrome などでもまだ完全な実装ではないっぽい。 @counter-style - CSS&colon; Cascading Style Sheets | MDN

Does not support as a value for the symbols descriptor.

https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style

 というかいずれ画像も使えるようになるのか、便利そう……。

Macで画面共有中でも通知バナーを出す

 「システム環境設定」→「通知と集中モード」の一番下の「ディスプレイをミラーリング中または共有中」のチェックボックスにチェックを入れると、画面共有中でも通知バナーが出る。これでメンションにも気づける (これをやらないと画面共有終わったときにドバッと通知が来る感じになって不便)。

 画面共有で共有されてはまずい通知が来そうなときはチェックを外しておく必要がありそう。メインモニタじゃない画面を共有してるならそもそも映らなくて安心とかはあるのかも?

support.apple.com

切る/切って落とす

何を? 切る? 落とす?
切る 落とす
火蓋 切る 落とさない
口火 切る 落とさない

火ぶたを切って落とす? | ことば(放送用語) - 放送現場の疑問・視聴者の疑問 | NHK放送文化研究所

 「火蓋(ひぶた)」は、「(昔の鉄砲の)火縄銃の火皿の火口をおおうふた」のことで、「火ぶたを切る」の本来の意味は「火縄銃の火蓋を開いて点火の用意をする。また、発砲する」(『日本国語大辞典小学館)ことです。
(中略)
 ところで、「~を切る」という慣用語の一つに「口火を切る」ということばがありますが、この「口火」も火縄銃に関係があります。もともとは「火縄銃の火ぶたに点火するための火」のことで、ここから「物事を始めるきっかけをつくる」という意味の「口火を切る」が生まれました。

https://www.nhk.or.jp/bunken/summary/kotoba/gimon/137.html

きょうの日本語検定:時事ドットコムきょうの日本語検定:時事ドットコム

「幕を切って落とす」は、元々歌舞伎の用語で、舞台の幕を一気に落として演技を始めることから、何かを華々しく開始することをいう。

https://www.jiji.com/jc/e?g=e07&d=20180512&ans=3