<h1><code>fsl</code> Cookbook</h1>

This is a gathering point for <code>.fslrc</code> snippets that do potentially useful things.  It can be surfed for snippets to take out and use directly or just as inspiration for other functionality.

<h2>Initial workflow fix</h2>

One of the annoyances of Fossil is that the usual workflow can be a bit tedious and repetitive.  The following interceptor adds a "cr:eate" command that solves this.  Its command line is as follows:

  <code>fsl cr(eate)

The interceptor does the following:

  #  Creates a new fossil repository in named by the
     current working directory (assumed to be where the project will live).  It
     gets its default settings from
  #  Opens the newly-created repository.
  #  If the optional password is given, sets the password on the Fossil user
     matching the logged-in user.
  #  Opens a new branch named "development".
  #  Switches to that new branch.

<code><verbatim>interceptor cr:create {
    global tcl_platform

    set repodir [file join [file normalize ~] Repositories]
    set reponame [file join $repodir [file tail [pwd].fossil]]
    set skeleton [file join $repodir skeleton.fossil]

    set user $tcl_platform(user)
    set password [lindex $params 1]

    fossil new $reponame --template $skeleton
    fossil open $reponame

    if {$password != ""} {
        fossil user password $user $password
    }

    fossil branch new development trunk
    fossil update development

    return {}


<hr><div id="a39e5758b078906a"><i>On 2012-12-29 13:53:21 UTC michael added:</i><br />
<h2>Making things garish</h2>

You can do a lot of stuff with filters.  Say, for example, that you want a busier <code>timeline</code> or <code>leaves</code> display.  The following filter will give it to you:

<code><verbatim>filter fancy_timeline {leaves timeline} {
    if {[regexp "^=== .* ===" $line]} {
        return [coloured green $line]
    }
    # Expressions to match:
    set artifact_rx
    set date_rx
    set current_rx
    set branch_rx
    # Colour the output (repeated substitutions on $line):
    set line [regsub -all $artifact_rx $line\
        [format {[%s%s]}\
            [coloured yellow [display bright
            [coloured yellow {\2}]]]
    set line [regsub $date_rx    $line [coloured blue &]]
    set line [regsub $current_rx $line [display reversed &]]
    set line [regsub $branch_rx  $line [display bright &]]
    # Values for user and tags may wrap, so left uncoloured:
    regsub -all {(user:|tags:)\s+} $line [coloured yellow &]


Be sure to also disable <code>log_entry</code> otherwise both filters
will be triggered. To do so either comment out <code>log_entry</code> or
clear its command list,

<verbatim>
filter log_entry {} {
    ...
}
</verbatim>

This is what it looks like:

<a alt="" title="Hosted by
</div id="a39e5758b078906a">

<hr><div id="160de22eaba8727e"><i>On 2012-12-30 14:16:50 UTC michael added:</i><br />
<h2>Cloning workflow fix</h2>

This interceptor is the other half of the pair begun with the "Initial workflow fix" interceptor.  Its command line is:

  <code>fsl dup(licate) url

The interceptor works as follows:

  #  Clones the repository at the provided URL into
     named by the current working directory.
  #  Opens the newly-cloned repository into the current working directory.
  #  Adds the current logged-in user to the user list.
  #  If the optional password is given, the user's password is changed to that.

<code><verbatim>interceptor dup:duplicate {
    global tcl_platform

    set repodir  [file join [file normalize ~] Repositories]
    set reponame [file join $repodir [file tail [pwd].fossil]]

    set user     $tcl_platform(user)
    set url      [lindex $params 1]
    set password [lindex $params 2]

    fossil clone $url $reponame
    fossil open $reponame

    if {$password != ""} {
        fossil user password $user $password
    }

    return {}
id="160de22eaba8727e">

<hr><div id="85088e0d75e458b8"><i>On 2013-01-17 09:29:19 UTC michael added:</i><br />
<h2>Purging <tt>MISSING</tt> files</h2>

This combination of an alias, a filter and an interceptor will purge all <tt>MISSING</tt> files from your repository.  Useful for those cases where you forget to <kbd>fossil rm</kbd> before using the real <kbd>rm</kbd>.

<code><verbatim># fsl purge
# Purge all files flagged as "MISSING".
alias capture_changes changes

filter captured_changes {capture_changes} {
    variable captured
    lappend captured $line
    return {}
}

interceptor purge {
    variable captured {}
    fossil capture_changes
    foreach line $captured {
        if [string match MISSING* $line] {
            regsub ^MISSING $line {} file
            fossil rm [string trim $file]
        }
    }
    return {}
id="85088e0d75e458b8">

<hr><div id="3dd418e8d91c8951"><i>On 2013-07-03 21:33:51 UTC added:</i><br />
<h2>Colouring the current branch</h2>

A simple filter for colouring the current branch:

<code><verbatim>
filter branch {br:branch} {
    switch -regexp $line {
        {^\*}   { coloured yellow $line }
        default {             set  line }
    }
}


Output,

<a title="Hosted by id="3dd418e8d91c8951">

<hr><div id="17598ce12c6e10e5"><i>On 2014-05-07 10:35:18 UTC fifr added:</i><br />
<h2>Interactive commit: record</h2>
During development it is sometimes convenient to be able to commit only some of the changes in the current working directory. Fossil allows to select some files to be included in the next commit, but it is not possible to select only few changes in one file. Note that it is arguable whether such partial commits are a good thing or not because they encourage the creation of checkins with untested code.

This modification adds a <code>record</code> command, which mimics Mercurial's extension]. It allows to interactively select hunks to be included in the next commit.

  <code>fsl record

The latest version of a fslrc file with this code is in the [/timeline?r=record|record branch] and can be found (just drop the code into your .fslrc file).

<a title="Hosted by
</div id="17598ce12c6e10e5">

<hr><div id="80a99c86c25c7500"><i>On 2016-04-24 16:18:19 UTC added:</i><br />
<h2>Controlling autosync</h2>
Useful aliases for controlling <code>autosync</code> behaviour:

<code><verbatim>
alias live  {set autosync on}
alias local {set autosync off}


then,

<code><verbatim>
$ fsl local
# ...work offline for a while...
$ fsl live

</div id="80a99c86c25c7500">

<hr /><div id="7ad517bc28152cf6"><i>On 2019-12-12 19:06:05 UTC added:</i><br />
<h2>Quick snapshots</h2>

To quickly snapshot the working tree (without reverting anything),

<code><verbatim>
interceptor snap {
  set now [clock format [clock seconds]]
  fossil stash snapshot -m "fsl snap @ $now"
  return {}
}


then,

<code><verbatim>
$ fsl snap
$ fsl stash ls
    1: [06a31756cc58f2] on 2019-12-12 19:05:22
       fsl snap @ Thu Dec 12 11:05:22 PST 2019


(inspired by Stephan Beal's <tt>fsnap</tt> <a id="7ad517bc28152cf6">