Author: 颖奇L’Amore
Blog: www.gem-love.com
MacOS高效使用文章合集:here
需求分析 ▸ 我基本上写代码分三种情况:
写个大项目,用框架之类的,会选择jetbrains公司的IDE,比如IDEA。但是太笨重
写脚本等,或者写简单的html页面(复杂的不会),一般是用vscode
对某些txt编辑一下,或者随手跑一个脚本,或者随便写两行代码,或者临时打开个编辑器记录几句话,这种时候vscode感觉还是过于笨重(尽管vscode已经非常轻量了),需要超级轻量的编辑器。
所以这篇文章主要分享一下我用的轻量级编辑器TextMate。以前一直用Sublime Text,用了三年多,也还可以,但是有时候有bug,于是终于在最近被我淘汰了。
TextMate ▸ 关于基本使用都默认就可以了,包括有一些转大小写等快捷键功能可以自行看一下说明。 这里主要介绍如何使用TextMate的Bundle功能,以python为例
代码模板 ▸ 进入Edit Bundle 在这个红框Insert内相当于是代码模板(下面的idioms等也是),可以添加一些自己常用的代码模板,不过我一般也不用它写复杂的程序,这里就简单编辑一下头的模板 输入py3摁tab即可自动填充代码模板:
运行脚本 ▸ 之前用sublime时直接打开一个脚本然后cmd+B就直接运行了,TextMate也可以一个快捷键直接运行
首先是Run Script,是在TextMate中运行脚本输出结果,但是我不能直接使用,提示python command not found
于是我手工修改了python的路径为我的python3的绝对路径: cmd + R 即可运行
不过我不喜欢这个内置的输出,因为如果是长时间跑脚本的话,他的输出会有延迟,还是在iTerm中直接运行该py文件比较方便,这时候就要用Run Script(Terminal)。但是由于它是用AppleScript调用iTerm,而AppleScript使用了一种过时的表达tell the current terminal
导致无法使用,需要修改,这是我修改后的版本:
#!/bin/bash [[ -z "$TM_FILEPATH " ]] && TM_TMPFILE=$(mktemp -t pythonInTerm) : "${TM_FILEPATH:=$TM_TMPFILE} " ; cat >"$TM_FILEPATH " # run script using either Terminal.app or iTerm.app # if iTerm is open or if TM_TERMINAL is set to iTerm then use iTerm # otherwise default to Terminal.app since that is standard. # 这里将自带终端改成了iTerm TP=${TM_TERMINAL:=iTerm} TPY=${TM_PYTHON:-python}
esc () { STR="$1 " ruby18 <<"RUBY" str = ENV['STR' ] str = str.gsub(/'/, "' \\\\'' ") str = str.gsub(/[\\" ]/, '\\\\\\0' ) print "'#{str}'" RUBY }
iTerm_running () { ruby <<"RUBY" all = `ps -U "$USER " -o ucomm` split = all.split("\n" ) if split.find { |cmd| 'iTerm' == cmd.strip } STDOUT.write 0 else STDOUT.write 1 end RUBY }
# 主要改了这个地方的AppleScript # 然后删除临时文件由rm -rf改成了移至垃圾桶,避免误删文件导致文件丢失(一般不会生成临时文件所以用了个if做判断) if [ "$TP " == iTerm ] || [ $(iTerm_running) == 0 ]; then osascript <<END tell application "iTerm" activate set newWindow to (create window with default profile) tell newWindow tell current session write text "clear; cd $(esc "${TM_DIRECTORY}"); /usr/bin/python3 $(esc "${TM_FILEPATH}"); if [ -f $(esc "${TM_TMPFILE}") ]; then mv $(esc "${TM_TMPFILE}") ~/.Trash; fi" end tell end tell end tell END else osascript <<- APPLESCRIPT tell app "Terminal" launch activate do script "clear; cd $(esc "${TM_DIRECTORY}"); /usr/bin/python3 $(esc "${TM_FILEPATH}");if [ -f $(esc "${TM_TMPFILE}") ]; then mv $(esc "${TM_TMPFILE}") ~/.Trash; fi" set position of first window to { 100, 100 } end tell APPLESCRIPT fi
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
文章来源: https://www.gem-love.com/2022/04/19/TextMate%EF%BC%9A%E8%BD%BB%E9%87%8F%E7%BA%A7%E4%BB%A3%E7%A0%81%E7%BC%96%E8%BE%91%E5%99%A8/ 如有侵权请联系:admin#unsafe.sh