Fossil User Forum

fossil shell outputting the repository name?
Login

fossil shell outputting the repository name?

fossil shell outputting the repository name?

(1) By Alfred M. Szmidt (ams) on 2020-04-02 21:56:23 [source]

I have several terminals open, and "fossil shell" is quite useful, but sometimes I get confused which terminal is which repository.  So it would be really helpful if "fossil shell" in an opened repository, or after a open command would output the name of the project.

I'm not sure what to suggest as the actual prompt though.

(2) By Dan Barbarito (danbarbarito) on 2020-04-03 03:14:03 in reply to 1 [link] [source]

+1 this idea. Maybe the prompt can look like this:

fossil (project-name)> 

(3) By Stephan Beal (stephan) on 2020-04-03 09:43:15 in reply to 1 [link] [source]

Done. Note, however, that the shell can run without a repository, in which case it says "no repo":

[stephan@lapdog:~/fossil/fossil/src]$ ../fossil shell
fossil (Fossil)> ^D
[stephan@lapdog:~/fossil/fossil/src]$ cd
# Outside of any repository:
[stephan@lapdog:~]$ fossil shell
fossil (no repo)> ^D

(4) By Alfred M. Szmidt (ams) on 2020-04-03 10:56:17 in reply to 3 [link] [source]

That was quick, thank you!

(5) By anonymous on 2020-04-04 00:29:57 in reply to 3 [link] [source]

.. shell can run without a repository, in which case it says "no repo"

Maybe in such case just show nothing instead, like the old-style: 'fossil>' ?

(6) By Stephan Beal (stephan) on 2020-04-04 06:08:06 in reply to 5 [link] [source]

i tried that and the inconsistency left me wondering whether or not i was using an older fossil version. It also seems less confusing to me to make explicitly clear to the user that no repo is available.

(7) By sebyte on 2020-04-05 04:35:42 in reply to 3 [link] [source]

Done. Note, however, that the shell can run without a repository, in which case it says "no repo":

May I humbly request that this feature be managed by the settings command, with local and global values (but obviously not versionable).

I work in a Fossil shell within an Emacs buffer with a header line that not only tells you which repository (database) you are communicating with, but also which checkout directory you are in. (I call it the IFI Fossil Interface for Emacs and I am soon to release a beta version to the community).

This feature also adds a significant constraint to the names you give your repositiories if you work in a Fossil shell (enhanced or otherwise); long names now squander valuable buffer/window/screen width.

The setting could be called verbose-shell-prompt, or words to that effect.

(8) By Stephan Beal (stephan) on 2020-04-05 09:12:55 in reply to 7 [link] [source]

i'm not at all keen on making this configurable (but it would have surprised me greatly had the request not been made) because that opens up a deep rabbit hole of potential configuration options. If it's a simple on/off or truncation, the next person will ask for printf-style formatting for more customization, e.g. to show the checkout path, repo file path, and/or project name and/or description, in any order, with optional ANSI coloring to differentiate the components. (Such is the nature of feature requests.)

That's just to say that i'm not personally currently willing to commit to making it configurable, but patches are always thoughtfully considered.

That said: i can see how a long project name could be annoying in the shell, but it's also annoying in the web interface (for the skins which put it in the header), and suspect that only a tiny minority of people use "annoyingly long" names in practice. Barring that one corner case, i consider the addition of the project name to the shell prompt to be a usability improvement.

(9) By anonymous on 2020-04-05 13:56:55 in reply to 8 [link] [source]

How about controlling this with an env variable, say FOSSIL_PS1. It's a shell prompt, so this is similar to PS1 var used to control command shell prompt.

When it's set, the prompt will show the repo name, otherwise the usual prompt.

In a way the new prompt could be expressed as

   FOSSIL_PS1="(\P)> "

\P expands to project name.

... rabbit hole, you're right, but this could be a shallow one.

(10) By Stephan Beal (stephan) on 2020-04-05 14:17:34 in reply to 9 [link] [source]

The amount of code for controlling the configuration via an environment variable or the db is identical, plus or minus a couple comment lines to set up a new db-side config option (those are almost entirely set up via a code generator), so it's the same rabbit hole, either way. Someone else is welcome to climb down it, but i'm not volunteering.

As soon as someone adds a config option to show the path to the repo or checkout, a request will come in to make it configurable as absolute or relative, and/or to truncate at a certain (configurable) length, and to configurably truncate at the start, middle, or end of the path. Rabbit hole...

Easter is next weekend...

(11) By sebyte on 2020-04-05 14:41:56 in reply to 10 [link] [source]

[...] it's the same rabbit hole, either way.

How about a compilation option; --with-{verbose|compact}-prompt?

(12) By anonymous on 2020-04-05 20:15:54 in reply to 10 [link] [source]

A little Easter egg here :)

Something like the test code below to make use of FOSSIL_PS1 env var?

\P would expand into "project" per repo. Possible to add other specifiers ... by popular demand.


/*
 BUILD-TEST:
   gcc ps1_test.c && FOSSIL_PS1=":\P> " ./a.out
   gcc -DTEST ps1_test.c && ./a.out

*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int set_prompt_string(const char *format, char *prompt)
{
  static const char *DEFAULT_PROMPT_FORMAT="> ";
  const char *fmt = format;

  const char *ps;
  char *pout;

  *prompt = 0;

  if (!fmt) fmt = getenv("FOSSIL_PS1");
  if (!fmt) fmt = DEFAULT_PROMPT_FORMAT;

  for (pout = prompt, ps = fmt; *ps; ++pout, ++ps) {
    /* process format specifiers */
    if (*ps == '\\') {
      ++ps;
      switch (*ps) {
      case 'P':  /* project-name*/
        strcpy(pout, "project");   /*TEST*/
        pout += strlen("project") - 1;
        continue;

      default:
        /* pass double-backslash and any unknown specifiers verbatim */
        if (*ps != '\\') --ps;
      }
    }
    *pout = *ps;
  }
  *pout = 0;

  return 0;
}

int main(int argc, char *argv[])
{
  char prompt[1024] = {0};

  const char *fmt = 0;

  if (argc > 1) {
    fmt = argv[1];
  }

#ifdef TEST
  {
    const char *formats[] = {
      "",">", "text","\\x","\\\\x","\\P","\\\\P","\\P> ","(\\P)> ",
      0
    };
    const char **f;

    for (f=formats; *f; ++f) {
       set_prompt_string(*f,prompt);
       printf("TEST|'%s' => '%s'\n", *f, prompt);
    }
    set_prompt_string(0,prompt);
    printf("TEST|'%s' => '%s'\n", "default", prompt);

    {
      char *env_var = "FOSSIL_PS1=(\\P) >";
      putenv(env_var);

      set_prompt_string(0,prompt);
      printf("TEST|'%s' => '%s'\n", env_var, prompt);
      putenv("FOSSIL_PS1=");
    }
  }
  return 0;
#endif

  set_prompt_string(fmt, prompt);
  printf("I|'%s' => '%s'\n", (fmt ? fmt : "default"), prompt);

  return 0;
}

(13.1) By sebyte on 2020-04-29 14:07:17 edited from 13.0 in reply to 10 [link] [source]

The fossil shell prompt reads 'no repo' when it is in a checkout directory if the checkout directory is unnamed. See transcript below.

fossil (no repo)> init foo.db
project-id: fd5e8e39a7effabe36f130bcacc1f64569fcbcb8
server-id:  fa5d7fb0a6d8a75453857329a5c261039c9c2541
admin-user: sebyte (initial password is "FGM3aAJohj")
fossil (no repo)> [ mkdir foo ]
fossil (no repo)> [ cd ~/fossil/sandpit/foo ]
fossil (no repo)> open ../foo.db
project-name: <unnamed>
repository:   /home/sebyte/fossil/sandpit/foo/../foo.db
local-root:   /home/sebyte/fossil/sandpit/foo/
config-db:    /home/sebyte/.fossil
project-code: fd5e8e39a7effabe36f130bcacc1f64569fcbcb8
checkout:     9860b436dba612263e7347bb645ca7ba0271955e 2020-04-29 13:46:57 UTC
tags:         trunk
comment:      initial empty check-in (user: sebyte)
check-ins:    1
fossil (no repo)> sql "INSERT INTO config VALUES ('project-name','foo',now())"
fossil (no repo)> [ Starting new shell process ... ]
fossil (foo)>

I suggest the prompt reads 'no name' in these situations.

Edit: Or perhaps 'unnamed' provides greater contrast and is therefore clearer.

(14) By Stephan Beal (stephan) on 2020-04-29 14:37:55 in reply to 13.1 [link] [source]

Fixed in the latest trunk. Thanks for the report:

$ f shell -R foo.fsl 
fossil (unnamed)> 
$ f shell 
fossil (no repo)>
$ f shell -R fossil.fsl 
fossil (Fossil)>