Skip to content

Instantly share code, notes, and snippets.

@lazymutt
Last active April 7, 2022 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazymutt/154b9c4c476ab293ae611bf28d26b030 to your computer and use it in GitHub Desktop.
Save lazymutt/154b9c4c476ab293ae611bf28d26b030 to your computer and use it in GitHub Desktop.
Runs flake8 against the current window/tab in BBEdit, displays results in new window. Shortens file paths in output.
-- Copyright (c) 2017 University of Utah Student Computing Labs.
-- All Rights Reserved.
--
-- Permission to use, copy, modify, and distribute this software and
-- its documentation for any purpose and without fee is hereby granted,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation, and that the name of The University
-- of Utah not be used in advertising or publicity pertaining to
-- distribution of the software without specific, written prior
-- permission. This software is supplied as is without expressed or
-- implied warranties of any kind.
--
--
-- flake8.scpt
-- 04/19/17, v1.0, todd.mcdaniel@utah.edu
--
-- Runs flake8 against the current BBEdit document, displays results in new window.
-- Shortens file paths
-- Requires flake8 to be installed.
-- Save this script in ~/Library/Application\ Support/BBEdit/Scripts/flake8.scpt
--
--
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
tell application "BBEdit"
activate
set filename to file of text window 1 as text
set docname to name of text window 1
end tell
set this_date to current date
set window_name to "flake8 output for " & docname & " on " & this_date
do shell script "/usr/local/bin/flake8 " & quoted form of the POSIX path of filename & " | /usr/bin/pbcopy"
set mylines to text of (get the clipboard)
set fixed_lines to replace_chars(mylines, POSIX path of filename, docname)
set the clipboard to fixed_lines
tell application "BBEdit"
activate
make new text window with properties {name:window_name}
paste
end tell
tell application "System Events" to key code 115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment