-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.tcl
58 lines (49 loc) · 1.14 KB
/
lib.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env tclsh
###############################################################################
# lib.tcl: helper variables and procedures for tcl utilities
###############################################################################
set LOGW "$::env(HOME)/log/wayland.log"
set LOGX "$::env(HOME)/log/x.log"
set ME [file tail $::argv0]
set TMPD "/tmp/_$::env(USER)"
set SESS {}
if {[info exist ::env(WAYLAND_DISPLAY)] && {} ne $::env(WAYLAND_DISPLAY)} {
set SESS w
}
if {{w} ne $SESS && [info exist ::env(DISPLAY)] && {} ne $::env(DISPLAY)} {
set SESS x
}
###############################################################################
proc err {s {nome {}}} {
if {{} eq $nome} {
global ME
puts -nonewline stderr "$ME: "
}
puts stderr "$s"
}
proc fail {s {nome {}}} {
err $s $nome
exit 1
}
proc ufail {body} {
global ME
fail "Usage: $ME $body" nome
}
proc need {args} {
set want false
foreach cmd $args {
if [catch {exec which $cmd}] {
set want true
err "need $cmd"
}
}
if {$want} {
exit 1
}
}
proc readfile {f} {
set h [open $f r]
set c [read -nonewline $h]
close $h
return $c
}