Skip to content

Instantly share code, notes, and snippets.

@PhilHudson
Created March 18, 2013 17:19
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 PhilHudson/5188974 to your computer and use it in GitHub Desktop.
Save PhilHudson/5188974 to your computer and use it in GitHub Desktop.
Files: ~/.screenrc ~/bin/short_day_name ~/bin/hr ~/bin/min ~/bin/sec ~/bin/copy-screen-copybuffer ~/bin/darwin/pbcopy
### .screenrc -*- mode: sh;-*-
# ==============================================================================
# Time-stamp: "2013-03-17 11:28:57 phil"
# ==============================================================================
defutf8 on
# Kill screen's startup message:
startup_message off
# Define a bigger scrollback, default is 100 lines:
defscrollback 100000
# Pick up the ultra-short host name. File contains just "setenv <prompt_host>"
source $HOME/.tcshrc.d/prompt_host
# Date-parsing scripts for use in hardstatus line:
backtick 1 0 0 $HOME/bin/short_day_name
backtick 2 1 1 $HOME/bin/hr
backtick 3 1 1 $HOME/bin/min
backtick 4 1 1 $HOME/bin/sec
# An alternative hardstatus to display a bar at the bottom listing the
# window names and highlighting the current window name in red.
hardstatus alwayslastline "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..K} ${PROMPT_HOST} %{..d}%y%{..W}%m%{..d}%d%{..W}%1`%{..d}%2`%{..W}%3`%{..d}%4` "
# Enter 'hardstatus alwayslastline' again to re-enable
#hardstatus alwaysignore
# Set screen's escape key to C-z rather than C-a (which is used by emacs/nano)
bind -c metakey z escape ^Za
bind ; command -c metakey
# Toggle status line:
# Display status line: C-z / =
bind -c hardstatus = hardstatus alwayslastline
# Hide status line: C-z / -
bind -c hardstatus - hardstatus alwaysignore
bind / command -c hardstatus
# Support for (typically remote) screen sessions displayed within screen
# sessions:
# Set 1st-level nested screen's escape key to C-J: C-Z a : escape ^Ja
bind -c metakey j eval meta stuff ":escape \^Ja\015"
# C-J a : escape ^\a
# Set 2nd-level nested screen's escape key to C-\:
bind -c metakey \\ eval meta stuff ":escape \^\\\015"
# Put copybuffer onto system clipboard: C-z b
bind b eval "writebuf ${HOME}/tmp/screen-copybuffer" "exec ${HOME}/bin/copy-screen-copybuffer"
# Execute .bash_profile on startup
shell -$SHELL
shelltitle Shell
# Use C-z instead of C-a as this makes more sense for Emacs
escape ^za
# Detach on hangup
autodetach on
# Allow multiple users
#multiuser on
vbell_msg " *beep* "
# emacs-style navigation in copy mode
#markkeys "\^=^a:h=^B:l=^F:$=^E"
## do not trash BackSpace, usually DEL
bindkey -k kb
bindkey -d -k kb
## do not trash Delete, usually ESC [ 3 ~
bindkey -k kD
bindkey -d -k kD
term $TERM
## start from $HOME
chdir
# ------------------------------------------------------------------------------
# STARTUP SCREENS
# ------------------------------------------------------------------------------
# One general-purpose shell session
screen -t Shell 0
utf8 on on
chdir
# One source control shell session
screen -t bzr 1
# Host- and OS-specific shell sessions, distinct hardstatus colors, etc.
# Just create an empty file if none required.
source $HOME/.screenrc.host
select 0
# Make sure screen has the correct PATH
# "a" is my tcsh alias for setting up my ssh agent via keychain
stuff "screen -X setenv PATH \"\$PATH\"; a\015"
# ==============================================================================
# .screenrc ends here
# ==============================================================================
#!/usr/bin/env bash
# Make sure we're using GNU `date', not BSD `date'
#!!! BASHISM !!! OSTYPE not in dash (?)
if [ "x${OSTYPE}x" = "xdarwinx" ]; then
# Use GNU date from MacPorts
DATE='/opt/local/bin/gdate'
elif [ "x${OSTYPE}x" = "xcygwinx" ]; then
DATE='/bin/date -R'
else
DATE='/bin/date'
fi
CUT='/usr/bin/cut'
while true; do
$DATE | $CUT -c 1-2 || exit 1
PREV_MIDNIGHT_SECONDS=`$DATE -d "00:00" +"%s"`
NOW_SECONDS=`$DATE +"%s"`
sleep $(( $PREV_MIDNIGHT_SECONDS + 86401 - $NOW_SECONDS ))
done
#!/bin/sh
date +%H
#!/bin/sh
date +%M
#!/bin/sh
date +%S
#!/usr/bin/env bash
# To be called by a GNU screen keybinding
screen_copybuffer_file="${HOME}/tmp/screen-copybuffer"
case "$OSTYPE" in
[Dd]arwin*)
pbcopy < "$screen_copybuffer_file"
;;
*)
xsel -i -b < "$screen_copybuffer_file"
;;
esac
#!/usr/bin/env bash
# Hack to get around GNU screen 4.00.03 not being able to use "proper" pbcopy
tmp_copy_file=`gmktemp --tmpdir screen_pbcopy.XXXXXX`
cat - > "$tmp_copy_file"
osascript <<EOF
tell application "System Events"
set the clipboard to (read posix file "$tmp_copy_file" as text)
end tell
EOF
rm "$tmp_copy_file"
unset tmp_copy_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment