Last active
August 28, 2016 18:55
-
-
Save markus1189/78e30c4487fb37587172d4fcb94e83e7 to your computer and use it in GitHub Desktop.
Manage scripts with Nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {}}: | |
with pkgs; | |
let | |
writePureScriptBin = { name, deps ? [], interp ? stdenv.shell }: text: | |
writeScriptBin name '' | |
#!${interp} | |
export PATH=${lib.makeBinPath deps} | |
${text} | |
''; | |
tmx = writePureScriptBin { name = "tmx.sh"; deps = [ tmux ncmpcpp zsh ]; } '' | |
set -e | |
function main() { | |
case "$1" in | |
"default") attach_or_create "default" "zsh";; | |
"sp_upper") attach_or_create "sp_upper" "zsh";; | |
"sp_lower") attach_or_create "sp_lower" "ncmpcpp";; | |
"sp_right") attach_or_create "sp_right" "zsh";; | |
"im") attach_or_create "im" 'ssh -t mc "tmux attach"';; | |
esac | |
} | |
function attach_or_create() { | |
if ! tmux has-session -t $1 &>/dev/null ; then | |
tmux new-session -s "$1" -d "$2" | |
fi | |
exec tmux -2 attach -t $1 | |
} | |
main $* | |
''; | |
git-pretty-log = writePureScriptBin { | |
name = "git-pretty-log.sh"; | |
deps = [ git gnused less ]; | |
} '' | |
HASH="%C(yellow)%h%Creset" | |
RELATIVE_TIME="%Cgreen(%ar)%Creset" | |
AUTHOR="%C(bold blue)<%aN>%Creset" | |
REFS="%C(red)%d%Creset" | |
SUBJECT="%s" | |
GPG="%C(yellow)%G?%Creset" | |
FORMAT="''${HASH} ''${RELATIVE_TIME} ''${AUTHOR} ''${REFS} ''${SUBJECT}" | |
pretty_git_log() { | |
git log --graph --color --pretty="tformat:''${FORMAT}" $* | | |
sed -Ee 's/(^[^<]*) ago\)/\1)/' | | |
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' | | |
less -FXRS | |
} | |
pretty_git_log $* | |
''; | |
in { inherit tmx git-pretty-log; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment