Skip to content

Some useful TextMate2 snippets, commands etc...

License

Notifications You must be signed in to change notification settings

vigo/textmate2-power-tools

Repository files navigation

Version Plaftorm Powered by Rake

TextMate2 - Power Tools

This bundle includes most used commands (on a daily basis) of me!...

Installation

cd ~/Library/Application\ Support/TextMate/Bundles/
git clone https://github.com/vigo/textmate2-power-tools.git PowerTools.tmbundle

# Restart your TextMate2

You need to install extra tools for Golang helper. You need to enable default Go Bundle from TextMate first...

$ go install golang.org/x/tools/cmd/goimports@latest
$ go install mvdan.cc/gofumpt@latest
$ go install github.com/segmentio/golines@latest
$ go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
$ go install honnef.co/go/tools/cmd/staticcheck@latest

$ brew install golangci-lint

Shellcheck feature requires shellcheck binary;

$ brew install shellcheck

You need to add your brew/bin path to PATH variable too:

$ command -v golangci-lint
/opt/homebrew/bin/golangci-lint     # my brew/bin is: /opt/homebrew/bin

# add to TextMate variable
PATH /opt/homebrew/bin:${PATH}

and you need to set:

  • TM_GOPATH and GOPATH get the value of $ go env GOPATH
  • TM_GO get the value of $ command -v go
  • GOMODCACHE get the value of $ go env GOMODCACHE
$ go env GOPATH           # (example) for TM_GOPATH and GOPATH => /Users/vigo/.local/go
$ go env GOMODCACHE       # (example) for GOMODCACHE  => /Users/vigo/.local/go/pkg/mod
$ command -v go           # (example) for TM_GO  => /opt/homebrew/opt/go/libexec/bin/go

$ defaults write com.macromates.TextMate environmentVariables \
    -array-add "{enabled = 1; value = \"$(command -v go)\"; name = \"TM_GO\"; }"
$ defaults write com.macromates.TextMate environmentVariables \
    -array-add "{enabled = 1; value = \"$(go env GOPATH)\"; name = \"TM_GOPATH\"; }"
$ defaults write com.macromates.TextMate environmentVariables \
    -array-add "{enabled = 1; value = \"$(go env GOPATH)\"; name = \"GOPATH\"; }"
$ defaults write com.macromates.TextMate environmentVariables \
    -array-add "{enabled = 1; value = \"$(go env GOMODCACHE)\"; name = \"GOMODCACHE\"; }"

Other bundle dependencies (not required but nice to have)


News

2024-05-28

  • Add uuid generator
  • Improve JavaScript runner, Bash Script Template

2023-12-23

  • Remove old django related snippets
  • Add new django related snippets (4+)

2023-06-27

  • Yeah, I’m still developing this bundle
  • Add - + create dynamic comment till your wrap column size!

2023-04-18

  • Add shellcheck disable comment via dis + TAB

2023-01-01

  • Add error tool tip max line length via TM_ERROR_TOOLTIP_MAX_LINE

2022-07-14

  • golangci-lint runner checks for TM_GOLANGCI_LINT_LOG_LEVEL environment variable. Due to go 1.18, golangci-lint produces some warnings. You can bypass those warnings via setting TM_GOLANGCI_LINT_LOG_LEVEL. Default is set to error (no more warnings).

2022-07-13

  • add fprf + , golang fmt.Fprintf snippet.

2022-06-03

  • golint removed, now using golangci-lint’s revive. (golint has been archived by the owner)

Available Items

  1. TextMate
  2. Django
  3. Python
  4. Ruby
  5. Rake
  6. Bash
  7. Markdown
  8. jQuery
  9. HTML
  10. Javascript
  11. Go
  12. Swift
  13. Lisp
  14. Elixir
  15. Git
  16. General
  17. Templates

TextMate Helpers

Scopes:

  • text.xml.plist

  • source.tm-properties

  • folder + : Add folder for info.plist

  • - + : Add delimeter for info.plist

  • prop + : Add properties for .tm_properties

    • excludes: excludeInFolderSearch / excludeInFileChooser
    • includes: include
    • spelling: spellingLanguage
  • "Show Environment Variables" for better, sorted and grouped env-var list


Django

Update

  • Improve Django snippets/helpers
  • Add Django REST generics and viewsets

Django Snippets

TAB completion Description
admin + Screenshot of: admin
admin + Screenshot of: admin
model + Screenshot of: model
meta + (Model meta options) Screenshot of: opt
fld + (For fields...) Screenshot of: fld
opt + (For field options...) Screenshot of: opt
hlp + (Helpers) Screenshot of: hlp
str + Injects def __str__(self):
save + Injects model save def save(self, *args, **kwargs):
does + Model.DoesNotExist
wr + (Management commands) self.stdout.write
ws + (Management commands) self.style
= + (Template) {{ variable }}
== + (Template) {% tag %}
ase + (Test) self.assertQuerysetEqual

Django Scope

You have a scope called: Python Django (Extended). Press + + + P for selecting this scope.


Python

You can prettify any kind of Python list or dict via + + P in any scope!

Python Snippets

TAB completion Description
ase + Screenshot of: ase
utf + # -*- coding: utf-8 -*-
p + Print with format: print(CURSOR.format())
pp + pp = pprint.PrettyPrinter(indent=4)
pr + Pretty Print with format: pp.pprint(CURSOR.format())
tern + Ternary expression helper
pdbg + Injects Python Debuffer
ipdbg + Injects IPython Debuffer
logger + Injects logger snippet
loggerbc + Injects logger snippet with basic config
+ ' Docstring
init + (Class) Injects def __init__ ...
@sm + (Class) Injects @staticmethod
@cm + (Class) Injects @classmethod
@pr + (Class) Injects @property
__ + (Class) Injects __str__ or __repr__
imp + (import) Injects import with some predefined package names
inject + (apped) Injects TM_PYTHON_FMT_VIRTUAL_ENV related appends to sys.path
= + (python) Injects python placeholder {}
. + (doctest) Injects >>>
+ + i Create __init__.py

hlp +

from __future__ import unicode_literals
                       print_function
                       division
                       absolute_imports

Ruby

You need to add Ruby on Rails bundle from Preferences/Bundles.

Ruby Snippets for ERB

Scope: text.html.erb

TAB completion Description
= + <%= CURSOR %>
if + ERB compatible if
each + ERB compatible each and each_with_index

Rake

Rake Snippets

tas +

  • Task with args

  • Task with args and dependecies

  • Task w/o description

  • tasr + : Creates remote-task skel

  • tasd + : Creates default task code

  • inv + : Creates Rake::Task...invoke + params

  • des + : desc "...." only

  • args + : args.with_defaults(...)


Bash

Added shellcheck linter/checker support. Use TM_SHELLCHECK_DISABLE to disable it! You need to install shellcheck via;

brew install shellcheck

If you already have shellcheck, set binary path to TM_SHELLCHECK:

# custom shellcheck path
defaults write com.macromates.textmate environmentVariables -array-add \
    '{ name = "TM_SHELLCHECK"; enabled = 1; value = "/path/to/shellcheck"; }'

# disable shellcheck
defaults write com.macromates.textmate environmentVariables -array-add \
    '{ name = "TM_SHELLCHECK_DISABLE"; enabled = 1; value = "1"; }'

You can disable shellcheck feature on your scripts via dis + TAB, this adds:

# shellcheck disable=all

comment.

You need to restart TextMate after these settings...

Bash Snippets

  • if + : if / else / elif template.
  • for + : Array iteration template
  • for + : Range iteration template
  • envi + : Inject some environment variables.

Markdown

Markdown Snippets

  • badge + : Adds img.shields.io badge!
  • + (: Fixes Parenthesis behavior.

jQuery

jQuery Snippets

  • each + : jQuery each code template
  • ready + : jQuery $(document).ready() code template
  • plug + : jQuery plugin skel.

HTML

HTML Snippets

  • more + : &rsquo;
  • + + S: Wrap selection with smart quotes.
  • + C: Wrap/unwrap code Inline
  • p + : <p>carret<p>
  • li + : <li>carret<li>

Javascript

Javascript Snippets

  • con + : Generates console.log, console.dir, console.warn, console.error, console.group, console.groupEnd skel
  • if + : if related code.
  • fun + : function related code.
  • for + : for related code.
  • swi + : switch related code.
  • load + : Injects window.addEventListener(...)

Javascript Commands

You need to install node locally and must define TM_NODE variable and set the executable path for node:

# example
defaults write com.macromates.textmate environmentVariables -array-add \
    '{enabled = 1; value = "/path/to/node"; name = "TM_NODE"; }'
  • + R: Runs javascript.

Go

When you hit + S, TextMate runs unless disabler environment variable(s) is/are set:

  • gofumpt
  • gofmt
  • goimports
  • golines
  • go vet + shadow
  • golangci-lint
  • staticcheck

You can disable format/lint feature (all of them) via setting TM_DISABLE_GO_LINTER environment variable.

You can disable linters piece by piece;

  • TM_DISABLE_GOFUMPT

  • TM_DISABLE_GOFMT

  • TM_DISABLE_GOIMPORTS

  • TM_DISABLE_GOLINES

  • TM_DISABLE_GOVET

  • TM_DISABLE_GOVET_SHADOW

  • TM_DISABLE_GOLANGCI_LINT

  • TM_DISABLE_STATIC_CHECK

Also you can configure golines via;

  • TM_GOLINES_MAX_LEN: Default value is 100
  • TM_GOLINES_TAB_LEN: Default value is 4

environment variables.

Use TM_GOLANGCI_LINT_LOG_LEVEL to by-pass linter warnings (go 1.18 issue):

  • TM_GOLANGCI_LINT_LOG_LEVEL to error shows only errors
  • TM_GOLANGCI_LINT_LOG_LEVEL to warning shows warnings too
  • TM_GOLANGCI_LINT_LOG_LEVEL to info show info level logs

Error tool tip had some issues, due to TextMate’s limit, lines > 150 chars was broken. Now it’s fixed. Use TM_ERROR_TOOLTIP_MAX_LINE environment variable to set your desired amount. Maximum is 150.

Go Commands

  • + R : Runs gofmt + goimports without save!

Go Snippets

  • fmt + : fmt.METHOD
  • spr + : fmt.Sprintf
  • prl + : fmt.Println
  • prf + : fmt.Printf
  • errf + : fmt.Errorf
  • tof + : reflect.TypeOf
  • log + : log.METHOD
  • if + : if conditions or obj, ok condition
  • for + : for conditions
  • str + : Define struct
  • fld + : Define struct field
  • ctp + : Inserts compile time proof fill place holders of var _ interface = (*struct)(nil)
  • seed + : Inserts random seeder
  • gcil + : Creates .golangci.yml under current working directory.
  • fprf + : fmt.Fprintf

.golangci.yml default config:

run:
  concurrency: 4
  timeout: 1m

linters-settings:
  revive:
    ignore-generated-header: true
    severity: warning
    rules:
      - name: exported
        severity: warning
        arguments:
            - "checkPrivateReceivers"
            - "sayRepetitiveInsteadOfStutters"
      - name: error-return
        severity: warning
      - name: error-naming
        severity: warning
      - name: if-return
        severity: warning
      - name: var-naming
        severity: warning
      - name: var-declaration
        severity: warning
      - name: receiver-naming
        severity: warning
      - name: errorf
        severity: warning
      - name: empty-block
        severity: warning
      - name: unused-parameter
        severity: warning
      - name: unreachable-code
        severity: warning
      - name: redefines-builtin-id
        severity: warning
      - name: superfluous-else
        severity: warning
      - name: unexported-return
        severity: warning
      - name: indent-error-flow
        severity: warning
      - name: blank-imports
        severity: warning
      - name: range
        severity: warning
      - name: time-naming
        severity: warning
      - name: context-as-argument
        severity: warning
      - name: context-keys-type
        severity: warning
      - name: indent-error-flow
        severity: warning
      - name: waitgroup-by-value
        severity: warning
      - name: useless-break
        severity: warning
      - name: struct-tag
        severity: warning

linters:
  disable-all: true
  enable:
    - asciicheck 
    - durationcheck 
    - errcheck 
    - errorlint 
    - exhaustive 
    - gosec 
    - govet 
    - makezero 
    - nilerr 
    - rowserrcheck 
    - exportloopref 
    - sqlclosecheck 
    - staticcheck 
    - typecheck 
    - bodyclose 
    - noctx 
    - prealloc
    - gosimple
  presets:
    - comment 
    - error 
    - format 
    - metalinter 
    - unused

issues:
  exclude-use-default: false

You can configure golangci via setting TM_GOLANGCI_LINT_MANUAL environment variable manually w/o config file. Example variable and value:

TM_GOLANGCI_LINT_MANUAL    -p comment -p error -p format -p metalinter -p unused -E gosimple -E asciicheck -E durationcheck -E errcheck -E errorlint -E exhaustive -E gosec -E govet -E makezero -E nilerr -E rowserrcheck -E exportloopref -E sqlclosecheck -E staticcheck -E typecheck -E bodyclose -E noctx -E prealloc

This works only if any of these file(s) is/are unset/not-exists in the project root:

  • .golangci.yml
  • .golangci.yaml
  • .golangci.toml
  • .golangci.json

Swift

You need to install/activate Swift Bundle from: TextMate > Preferences > Bundles.

Swift Snippets

  • p + : Print statement
  • typ + : Type of object
  • = + : Variable safe print
  • des + : Describe object

Lisp

You need to install/activate Lisp Bundle from: TextMate > Preferences > Bundles. Please set TM_CLISP variable for executer. You can install from brew: brew install clisp

# example
defaults write com.macromates.textmate environmentVariables -array-add \
    '{enabled = 1; value = "/usr/local/bin/clisp"; name = "TM_CLISP"; }'

Lisp Snippets

  • p + : Print

Lisp Commands

  • + R: Run.

Elixir

You need to install/activate Elixir Bundle:

cd ~/Library/Application\ Support/TextMate/Bundles/
git clone https://github.com/elixir-lang/elixir-tmbundle.git Elixir.tmbundle

Elixir Snippets

  • p + : Print or Inspect
  • #: Select text in quotes then press # (Ruby’s string interpolation-ish)

Git

Press + + B for;

  1. Git blame current line
  2. Git blame current line for last N commit

General

TAB completion Description
dateT + Screenshot of: dateT
lorem + Screenshot of: lorem
+ ' Single smart apostrophe. (Works in html, text, markdown, yaml)
applek + Generate apple symbols like: ⌘ ⎋ more...
applek + Generate apple symbols inside of <kbd> tags.
- + Dynamic comment. Fills remaning line with -
-- + Line delimeter, 80 charts comment # ---- ...
--- + Dynamic tilda. Fills remaning line with ~
+ + B Shows git blame for current line

Templates

Language Scope TAB Completion
BASH source.shell temp +
Python source.python temp +
Python source.python temp + with Doctests
Python source.python temp + with Logging
Golang source.go temp +
HTML -no scope required- html5 +
HTML with Bulma -no scope required- html5 + with Bulma.io CSS
Vue Component text.html.vue temp +

Contributor(s)

License

This project is licensed under MIT.

About

Some useful TextMate2 snippets, commands etc...

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages