dsc set opt "" -- unset value, make it default one
dsc get opt -- get option's value, maybe default one
dsc get opt/* -- list /*/ sections
- dsc diff [prefix] -- show the difference between committed and current
+ dsc diff [prefix] -- show the difference between saved and stash
dsc revert opt -- revert opt's configuration
dsc commit -- commit (save) configuration
dsc export >file.txtar -- export whole configuration
dsc import <file.txtar -- import it
Environmental variables:
- $DSC_SCHEMA -- path to the schema definition
- $DSC_CURRENT -- path to current/unsaved configuration state
- $DSC_COMMITTED -- path to committed/saved state
+ $DSC_SCHEMA -- path to the schema definition
+ $DSC_STASH -- path to stashed/unsaved state
+ $DSC_SAVED -- path to committed/saved state
There are two kinds of options:
* array/list ones, which are identified with /*/ in "list"'s
}
if {[catch {set Schema $env(DSC_SCHEMA)}]} {set Schema schema}
-if {[catch {set Curr $env(DSC_CURRENT)}]} {set Curr current}
-if {[catch {set Comm $env(DSC_COMMITTED)}]} {set Comm committed}
+if {[catch {set Stash $env(DSC_STASH)}]} {set Stash stash}
+if {[catch {set Saved $env(DSC_SAVED)}]} {set Saved saved}
proc walk {root typ} {
set rv [list]
}
proc assure-exists {opt} {
- global Curr
- if {! [file exists $Curr/$opt]} {
+ global Stash
+ if {! [file exists $Stash/$opt]} {
puts stderr "not found"
exit 1
}
set dir [file dirname $opt]
set tail [run-checker $opt [file tail $opt]]
set tail [string trimright $tail "\n"]
- file mkdir $Curr/$dir/$tail
+ file mkdir $Stash/$dir/$tail
puts $dir/$tail
}
del {
if {$opt != ""} {
assure-exists $opt
}
- file delete -force $Curr/$opt
+ file delete -force $Stash/$opt
}
set {
if {[llength $argv] == 2} {
set v [lindex $argv 2]
}
if {$v == ""} {
- file delete $Curr/$opt
+ file delete $Stash/$opt
exit
}
set v [run-checker $opt $v]
- file mkdir "$Curr/[file dirname $opt]"
- set fh [open $Curr/$opt w]
+ file mkdir "$Stash/[file dirname $opt]"
+ set fh [open $Stash/$opt w]
puts -nonewline $fh $v
close $fh
}
if {[file tail $opt] == "*"} {
set opt [file dirname $opt]
assure-exists $opt
- set dirs [glob -directory $Curr/$opt -types d -tails -nocomplain -- *]
+ set dirs [glob -directory $Stash/$opt -types d -tails -nocomplain -- *]
foreach dir [lsort $dirs] {
puts $dir
}
exit
}
- if {[file exists $Curr/$opt]} {
- puts -nonewline [fileread $Curr/$opt]
+ if {[file exists $Stash/$opt]} {
+ puts -nonewline [fileread $Stash/$opt]
exit
}
puts -nonewline [run-checker $opt ""]
}
diff {
- set fh [file tempfile dirsComm]
- foreach fn [walk $Comm/$opt d] {
- puts $fh [string range $fn [string length $Comm]+1 end]
+ set fh [file tempfile dirsSaved]
+ foreach fn [walk $Saved/$opt d] {
+ puts $fh [string range $fn [string length $Saved]+1 end]
}
close $fh
- set fh [file tempfile dirsCurr]
- foreach fn [walk $Curr/$opt d] {
- puts $fh [string range $fn [string length $Curr]+1 end]
+ set fh [file tempfile dirsStash]
+ foreach fn [walk $Stash/$opt d] {
+ puts $fh [string range $fn [string length $Stash]+1 end]
}
close $fh
- set fh [open "| diff -u -L dirs/committed -L dirs/current
- $dirsComm $dirsCurr" r]
+ set fh [open "| diff -u -L dirs -L dirs $dirsSaved $dirsStash" r]
puts -nonewline [read $fh]
catch {close $fh}
- file delete $dirsComm
- file delete $dirsCurr
- set fh [open "| diff -urN $Comm/$opt $Curr/$opt" r]
+ file delete $dirsSaved
+ file delete $dirsStash
+ set fh [open "| diff -urN $Saved/$opt $Stash/$opt" r]
puts -nonewline [read $fh]
catch {close $fh}
}
revert {
- catch {file delete -force $Curr/$opt}
- catch {file copy $Comm/$opt $Curr/$opt}
+ catch {file delete -force $Stash/$opt}
+ catch {file copy $Saved/$opt $Stash/$opt}
}
commit {
- file delete -force $Comm.bak
- set tmp $Comm.[expr {int(rand() * 1000000)}]
- file copy $Curr $tmp
- file rename $Comm $Comm.bak
- file rename $tmp $Comm
- file delete -force $Comm.bak
+ file delete -force $Saved.bak
+ set tmp $Saved.[expr {int(rand() * 1000000)}]
+ file copy $Stash $tmp
+ file rename $Saved $Saved.bak
+ file rename $tmp $Saved
+ file delete -force $Saved.bak
}
export {
- set dirs [walk $Comm d]
+ set dirs [walk $Saved d]
puts "-- .dirs --"
foreach fn $dirs {
- puts [string range $fn [string length $Comm]+1 end]
+ puts [string range $fn [string length $Saved]+1 end]
}
foreach dir $dirs {
foreach fn [walk $dir f] {
- puts "-- [string range $fn [string length $Comm]+1 end] --"
+ puts "-- [string range $fn [string length $Saved]+1 end] --"
puts -nonewline [fileread $fn]
}
}
set fn ""
set lines [list]
proc filewrite {fn v} {
- global Curr
+ global Stash
if {[llength $v] == 0} {
return
}
if {$fn == ".dirs"} {
foreach dir $v {
- file mkdir $Curr/$dir
+ file mkdir $Stash/$dir
}
return
}
- file mkdir [file dirname $Curr/$fn]
- set fh [open $Curr/$fn w]
+ file mkdir [file dirname $Stash/$fn]
+ set fh [open $Stash/$fn w]
puts $fh [join $v "\n"]
close $fh
}