Atom に日付時刻を入力するショートカットキーを追加
ATOMで作業ログを残したいとき、日付時刻を入れるショートカットが見つからなかったので追加。
環境はMacOS10.14.4 でJISキーボード。 ATOMのファイルを2点変更して、以下のような感じにした。
cmdと; を押すとYYYY/MM/DD(曜日)を出力 例. 2019/04/27(土) cmdとctrlと; を押すとhh:mm:ssを出力 例. 17:20:00 cmdと: を押すと上記のどちらも出力 2019/04/27(土) 17:20:39
まるまる参考にしたのはこちら。Dateパッケージを使う方法もあるけど、曜日も入ってほしい。
- Atomのinit.coffeeファイルに以下を追加
~/.atom/init.coffee
################################################################ # 現在日時を挿入するコマンドを追加 # 参考: https://github.com/dannyfritz/atom-date # 参考: https://github.com/JerrySievert/date-utils daysKanji = ['日', '月', '火', '水', '木', '金', '土'] pad = (str, length) -> str = String(str) str = '0' + str while(str.length < length) str dateOrTime = (kind) -> now = new Date() yyyy = now.getYear() + 1900 mm = pad(now.getMonth() + 1, 2) dd = pad(now.getDate(), 2) ddd = daysKanji[now.getDay()] hh24 = pad(now.getHours(), 2) mi = pad(now.getMinutes(), 2) ss = pad(now.getSeconds(), 2) if kind == 1 "#{yyyy}/#{mm}/#{dd}(#{ddd})" else if kind == 2 "#{hh24}:#{mi}:#{ss}" else "#{yyyy}/#{mm}/#{dd}(#{ddd}) #{hh24}:#{mi}:#{ss}" insertText = (str) -> return unless editor = atom.workspace.getActiveTextEditor() selection = editor.getLastSelection() selection.insertText(str) atom.commands.add 'atom-text-editor', 'torout-date:date', -> insertText(dateOrTime(1)) atom.commands.add 'atom-text-editor', 'torout-date:time', -> insertText(dateOrTime(2)) atom.commands.add 'atom-text-editor', 'torout-date:datetime', -> insertText(dateOrTime(0)) ################################################################
- ATOMのキーマップファイルに以下を追加
~/.atom/keymap.cson
'atom-text-editor': 'cmd-;': 'torout-date:date' 'cmd-ctrl-;': 'torout-date:time' 'cmd-:': 'torout-date:datetime'
これでATOMを一旦終了して再起動したら動いた。いい感じ。 後でキーバインドを調べると他にcmd-: を使うものもあったみたいだけど、問題なさそうなのでこれで動かしてます。
AWS cloud9からローカル環境へRails環境を移行
Rails Tutlial を4章まで進めて以降、諸事情で再開まで3ヶ月ほど経ったので再開がてらローカル開発環境を構築します。
これまでは公式ドキュメントのお勧め通りにAWS cloud9 を使用。
MacOS:Mojave 10.14.4
まずはrails のインストール
$ printf "install: --no-rdoc --no-ri\nupdate: --no-rdoc --no-ri\n" >> ~/.gemrc $ gem install rails -v 5.1.6 Fetching: concurrent-ruby-1.1.5.gem (100%) ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
早速エラーになったので調べる。
gem installでpermissionエラーになった時の対応方法
上記を参考に対応。
$ which gem /usr/bin/gem $ which ruby /usr/bin/ruby $ brew update -bash: brew: command not found
Homebrewが先に必要だった。
xcode を入れる。
$ xcode-select --install xcode-select: error: command line tools are already installed, use "Software Update" to install updates
不要だった。別の作業してた時にコマンドラインツールを入れてたらしい。
Homebrew パッケージマネージャを入れる。
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" $ brew doctor $ brew update Already up-to-date.
rbenv Rubyバージョンを管理してくれるものを入れる。
$ brew install rbenv ruby-build $ rbenv install -l $ rbenv install 2.5.3 ruby-build: use openssl from homebrew Downloading ruby-2.5.3.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.bz2 Installing ruby-2.5.3... Installed ruby-2.5.3 to /Users/sugeta/.rbenv/versions/2.5.3
rbenv のバージョンを確認。
$ rbenv versions * system (set by /Users/sugeta/.rbenv/version) 2.5.3
使われるものを変更。
$ rbenv global 2.5.3
$ rbenv versions system * 2.5.3 (set by /Users/sugeta/.rbenv/version)
続いて環境変数に追加。
$ cd ~ $ vi .bash_profile
[[ -d ~/.rbenv ]] && \ export PATH=${HOME}/.rbenv/bin:${PATH} && \ eval "$(rbenv init -)"
参考:rbenvによるRubyのインストールからHello, World!まで
$ gem install rails -v 5.1.6 $ rails -v Rails 5.1.6
$ cd $ mkdir environment $ cd environment/ $ rails new testapp $ cd testapp $ bundle exec rails s
ここまででとりあえずRails環境構築OK! このあと、cloud9上で作ったものを持って来たい・・・
$ git config --global user.name "hogehoge" $ git config --global user.email hogehoge@gmail.com
bitbucket側で非公開のチェックを外してからgit cloneしたら行けた。
$ git clone https://hogehoge@bitbucket.org/hogehoge/sample_app.git $ ls sample_app/ Gemfile Rakefile config.ru package.json vendor Gemfile.lock app db public Guardfile bin lib test README.md config log tmp
あとはbundle install したいので
$ less Gemfile.lock BUNDLED WITH 1.17.3
bundler -v 1.17.3 を入れる
$ gem install bundler -v 1.17.3 Fetching: bundler-1.17.3.gem (100%) Successfully installed bundler-1.17.3 1 gem installed
AWS cloud9 上ではHiroku用にproductionでpostgres、developmentでsqliteを使う設定になっていたので以下のようにする
$ bundle install --path vendor/bundle --without production $ bundle exec rails s
workした!
続いてbitbucketからgithubへの移行をする。やり方はシンプルだった。
ここで以下例のbitbucketリポジトリを入力。 https://hogehoge@bitbucket.org/hogehoge/sample_app.git
git push の先をbitbucketからgithubに変更した。
git remote set-url origin https://github.com/hogehoge/fugafuga.git
Heroku の設定
$ brew install heroku/brew/heroku $ heroku --version
ログインとSSHキーの追加
$ heroku login $ heroku keys:add
Herokuでアプリを作成しようとしたところ5個に達してるとのエラーあり
$ heroku create Creating app... ! ▸ You've reached the limit of 5 apps for unverified accounts. Delete some apps or add a credit card to verify your account.
現在のアプリを以下のコマンドで確認
$ heroku apps
以下形式のコマンドで不要なものを削除
$ heroku apps:destroy --app アプリ名 --confirm アプリ名
改めてアプリ作成して成功 URLにアクセスして「Heroku | Welcome to your new app!」と表示されることを確認
$ heroku create Creating app... done, ⬢ secret-taiga-xxxxx https://secret-taiga-xxxxxx.herokuapp.com/ | https://git.heroku.com/secret-taiga-xxxxx.git ```` Heroku にプッシュして動作を確認
$ git push heroku master
ここまで!想定してた作業が一区切りついていい感じ。