LoginSignup
3
2

More than 5 years have passed since last update.

なでしこを使ってWindowsのテキストエディタで一時的なメモファイルを快適に作成する

Last updated at Posted at 2017-12-14

Motivation

Emacs の open-junk-file と同じノリです。

作業ログは随時逐一事細かにファイルに記録しておきたいものです。

だいたいその日ごとにいろんなトピックのタスクが発生するのですが、
毎回その日のファイルを作って、どこに保存するか決めて、ファイル名決めて・・・っていうのはだるいですよね。

手軽にメモを作成したい!
そこを解決するライフハックです。
ランタイムとして なでしこ 1系が必要です。

Goal

  1. Ctrl+Alt+J を押してファイル名の残りを入力すれば自動的に yyyy/MM/dd/yyyyMMdd-HHmmss- というファイルが作成され、エディタが起動するという代物です。
  2. Dropbox, GoogleDrive, ownCloud 等のクラウドストレージと連携していれば保存した瞬間同期されて、どこでもそのメモを参照できるのでとても便利です。

How to

  • 以下のスクリプトをどこか好きな場所に置きます。

junk_base_dir, emeditor="C:\Users\Programs Files\EmEditor\EmEditor.exe" はそれぞれ保存ベースとなるディレクトリのパス、エディタの実行ファイルのフルパスで置き換えて下さい。

junkfile.nako
母艦の可視はオフ
junk_base_dir=「C:\Users\fred\ownCloud\Documents\memos」
today=今日
now=今
todayの「/」を「\」に置換
junk_dir="{junk_base_dir}\{それ}"
today_hyphen=todayの「/」を「-」に置換
now_hms=nowの「:」を「」に置換
filename_prefix="{today_hyphen}-{now_hms}-"
filename_prefixを表示
ダイアログ初期値はfilename_prefix
「Input Junk File Name」で尋ねる
もしそれがいいえならば
    おわり
違えば
    junk_file_nameはそれ
    junk_dirのフォルダ作成
    junkfile="{junk_dir}\{junk_file_name}"
    「」をjunkfileに保存
    emeditor="C:\Users\Programs Files\EmEditor\EmEditor.exe"
    "{emeditor} {junkfile}"をコマンド実行
    おわり
  • 保存した場所の例

2017-12-14_13h06_58.png

  • デスクトップ等適当な場所にショートカットを作成します

2017-12-14_13h07_19.png

  • ショートカットキーを割り当てます

2017-12-14_12h27_32.png

Usage

  • Ctrl+Alt+J をタイプするとファイル名を聞いてきます。

2017-12-14_12h27_50.png

  • 残りのファイル名を埋めて拡張子を書きましょう。

2017-12-14_12h27_57.png

  • ッターンとやると年月日のディレクトリの下にファイルが作成され、エディタが起動してすぐ編集できる状態になります。

2017-12-14_12h29_32.png

快適。

英語版の Windows だとなでしこ1は非ユニコードアプリケーションなので、これ使えないので↓を使うことにする。

入門したてなのでくっそ汚いプログラムになっています。

Open junkfile golang windows version.

junkfile.go
package main

import (
  "fmt"
  "time"
  "bufio"
  "io/ioutil"
  "os"
  "os/exec"
  "strings"
)

func main() {
    //fmt.Println("hello, world")
    nowTime := time.Now()
    const yyyymmdd = "2006/01/02"
    const ymdhis = "20060102-150405"
    str1 := nowTime.Format(yyyymmdd)
    str2 := nowTime.Format(ymdhis)
    fmt.Printf("now -> %s\n", str1)
    fmt.Printf("now -> %s\n", str2)
    reader := bufio.NewReader(os.Stdin)

    fmt.Print(str2, "-")

    text, _ := reader.ReadString('\n')
    text = strings.TrimSuffix(text, "\r\n")
    //text = text[:len(text)-2]
    fmt.Println(text)

    folderPath := "D:/Users/wnoguchi/Dropbox/Documents/junk/" + str1
    os.MkdirAll(folderPath, os.ModePerm)

    filePath := folderPath + "/" + str2 + "-" + text
    fmt.Println(filePath)
    d1 := []byte("")
    //err := ioutil.WriteFile(filePath, d1, os.ModePerm)
    ioutil.WriteFile(filePath, d1, os.ModePerm)

    //if err := os.MkdirAll("hoge/fuga", 0777); err != nil {
    //    fmt.Println(err)
    //}

    //C:\Program Files\EmEditor\EmEditor.exe
    //cmd:= exec.Command("cmd","/C","start","C:/Program Files/EmEditor/EmEditor.exe", filePath)
    cmd:= exec.Command("C:/Program Files/EmEditor/EmEditor.exe", filePath)
    //err:=cmd.Start()
    cmd.Start()
    //panic(err)
}

なでしこ愛

なでしこは日本語プログラミング言語です。

最近 JavaScript で動く なでしこ3 がでました。
トランスパイルとかしてるのだろうか。Web に特化してるのかな?
また、なでしこ2 は C# で開発されているので .NET のランタイムが動作する環境であればどこでも動きます。そう、 Mono ならね。
上記は現行のなでしこ 1 系のおはなしです。

References

  1. Emacs で使い捨てファイルを開く - Qiita
  2. なでしこ:日本語プログラミング言語
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2