Skip to content

Instantly share code, notes, and snippets.

View treyharris's full-sized avatar

Trey Harris treyharris

View GitHub Profile
# Clear scrollback buffer portably
if [[ $TERM_PROGRAM =~ 'Apple_Terminal' ]]; then
clear
printf '\e[3J'
elif [[ $TERM_PROGRAM =~ 'iTerm2' ]]; then
printf '\e]50;ClearScrollback\a'
fi
@treyharris
treyharris / showshell.zsh
Created May 12, 2015 17:41
zsh library for demonstrating sequences of commands
#!/bin/zsh
## Show shell commands in progress
## Usage:
## source $thisFile
##
# show "Explanation" "
# cmd 1
# cmd 2"
banner() {
@treyharris
treyharris / id-example.zsh
Last active February 28, 2020 12:26
Example of why ident attribute doesn't work in Git like CSV/SVN
#!/bin/zsh
# Make any non-zero return fatal just in case
setopt err_exit
source =(curl https://gist.githubusercontent.com/treyharris/c486c9f8776802e270b7/raw/2d0519826f3b8ca8446f59211ecd0dc738221d3d/showshell.zsh 2> /dev/null)
local dir=/tmp/ident-test
local files=5
@treyharris
treyharris / git-ident.md
Last active February 11, 2021 14:22
Why ident attribute doesn't work in Git like CSV/SVN

Why the ident attribute doesn't work in Git like in CVS or SVN

This is a wrinkle that people often don't get about the ident attribute: in CVS or Subversion, it would be legitimate to have a VERSION file containing nothing but $Id$ as a way of tracking that the right push had happened; if you did that with git, you'd get nothing useful. If you run the script below (or just read it and the output that follows), you can see why.

(Please direct comments on this to https://plus.google.com/+TreyHarris/posts/KRgNG3zDk9x.)

How do you do it?

Setting it up in Git is relatively simple. You create (or edit) the file .gitattributes and add a line telling Git to replace $Id$ when found in files that match certain filenames:

# Just skip the theme.
echo From the trey theme >&2
touch /tmp/trey-theme-run
export MY_NO_ZSH_THEME=1
# Need a token for homebrew calls to GitHub.
function {
local _homebrew_github_pat_file=~/.homebrew-github-token
if [[ -f "${_homebrew_github_pat_file}" ]]; then
export HOMEBREW_GITHUB_API_TOKEN=$(cat "${_homebrew_github_pat_file}")
elif _is_interactive_shell; then
export HOMEBREW_GITHUB_PAT_FILE="${_homebrew_github_pat_file}"
echoerr \
"No GitHub Personal Access Token for Homebrew. You may be rate-limited.
Run 'homebrew_github_token' for details."
@font-face {
font-family: octicons-anchor;
src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKwiAppcA9LtzKLSkdNhKFY3HF4lK69ExKslx7Xa+vPRVS43G98vG1DnkDMIBUgFN0MDXflU8tbaZOUkXUH0+U27RoRpOIyCKjbMCVejwypzJJG4jIwb43rfl6wbwanocrJm9XFYfskuVC5K/TPyczNU7b84CXcbxks1Un6H6tLH9vf2LRnn8Ax7A5WQAAAHicY2BkYGAA4teL
/*
* Trey's Markdown Here primary styling css, updated 2015-09-06
* NOTE:
* - The use of browser-specific styles (-moz-, -webkit-) should be avoided.
* If used, they may not render correctly for people reading the email in
* a different browser than the one from which the email was sent.
* - The use of state-dependent styles (like a:hover) don't work because they
* don't match at the time the styles are made explicit. (In email, styles
* must be explicitly applied to all elements -- stylesheets get stripped.)
*/
@treyharris
treyharris / colors.py
Last active December 19, 2015 22:02
Python script for demoing terminal colors
#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349
print "Color indexes should be drawn in bold text of the same color."
print
colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
"%02x/%02x/%02x" % (r, g, b)
for r in colored
@treyharris
treyharris / primary-styling.css
Created February 2, 2016 17:43
Markdown Here CSS
/*
* NOTE:
* - The use of browser-specific styles (-moz-, -webkit-) should be avoided.
* If used, they may not render correctly for people reading the email in
* a different browser than the one from which the email was sent.
* - The use of state-dependent styles (like a:hover) don't work because they
* don't match at the time the styles are made explicit. (In email, styles
* must be explicitly applied to all elements -- stylesheets get stripped.)
*/