output asked headers in the order they were asked; avoid header name spoofing by...
[hband-tools.git] / user-tools / kt
blob7ae0005a02efea7f418caab69bc55893328a66b6
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 kt - Run command in background terminal; keept(1) convenience wrapper
10 =head1 SYNOPSIS
12 kt [jobs | I<COMMAND> I<ARGS>]
14 =head1 DESCRIPTION
16 Run I<COMMAND> in a keept(1) session, so you may send it to the background
17 with all of its terminal I/O, and recall with the same C<kt COMMAND ARGS>
18 command.
20 Call C<kt jobs> to show running command sessions.
22 =head1 FILES
24 Stores control files in F<~/.cache/keept>.
26 =head1 SEE ALSO
28 keept(1)
30 =cut
32 EOF
35 if [ $# = 0 -o "$1" = --help ]
36 then
37 echo "Usage: kt [jobs | <COMMAND> <ARGS> ...]"
38 echo "Run COMMAND in a background terminal, which you can re-attach to with the same command."
39 echo "\"kt jobs\" list running jobs."
40 echo "See keept(1) which does the heavy lifing."
41 exit
44 if [ "$1" = jobs ]
45 then
46 for cmdfile in ~/.cache/keept/kt-*.txt
48 socket=${cmdfile:0:-4}
49 if grep -q "$socket" /proc/net/unix
50 then
51 started=`stat -c %y "$socket" | cut -f1 -d.`
52 cmd=`cat "$cmdfile"`
53 pwd=`cat "$socket.cwd"`
54 echo "$started $pwd $cmd"
56 done
57 exit
60 command_hash=`echo -n "$*" | md5sum | cut -c 1-32`
62 set -e
64 mkdir -p ~/.cache/keept
66 pwd > ~/.cache/keept/kt-$command_hash.cwd
67 echo "$@" > ~/.cache/keept/kt-$command_hash.txt
69 exec keept bwut ~/.cache/keept/kt-$command_hash "$@"