github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/integrations/git_any.mx (about)

     1  private git-refs {
     2      # Returns a map of branches and tags excluding checked-out branch in the current git repository
     3      
     4      map {
     5          git branch -a --format='%(refname:strip=2)' \
     6              -> [ :0 ] -> !match '*' \
     7              -> regexp (s,^origin/,,)
     8          git tag --format='%(refname:strip=2)' \
     9              -> regexp (s,^origin/,,)
    10      } {
    11          git branch -a --format='%(refname:strip=0)' \
    12              -> [ :0 ] -> !match '*' \
    13              -> prefix "Branch Ref: "
    14          git tag --format='%(refname:strip=0)' \
    15              -> prefix "Tag Ref: "
    16      } 
    17  }
    18  
    19  autocomplete set git %[{
    20      DynamicDesc: '{
    21          cast json
    22  
    23          # extract git commands from `git help`
    24          git help -a -> @[..^Ancillary]re -> tabulate: --map -> set commands
    25  
    26          # list all the git aliases
    27          git config --list -> regexp %(f/alias\.(.*)$/) -> foreach --jmap alias {
    28              $alias -> regexp %(f/^(.*?)=)
    29          } {
    30              $alias -> regexp %(f/=(.*)$) -> prefix %(alias: )
    31          } -> set aliases
    32  
    33          # merge the two JSON objects
    34          $commands <~ $aliases
    35  
    36          # return results
    37          out $commands
    38      }'
    39      IncManPage: true
    40      ListView: true
    41      FlagsDesc: {
    42          # `git config` isn't included in `git help`
    43          config: "Get and set repository or global options" # doesn't get added from `git help`
    44      }
    45      FlagValues: {
    46  
    47          add: [{
    48              AllowMultiple: true
    49              AllowAny: true
    50              Dynamic: '{
    51                  # files highlighted in `git` as modified but not staged
    52                  git -c color.ui=no status -s \
    53                      -> regexp %(f/^.[^\s] ["]?(.*?)["]?$/) \
    54                      -> cast str
    55              }'
    56          }]
    57  
    58          branch: [{
    59              Flags: [-d --delete]
    60              FlagValues: {
    61                  -d:       [{ DynamicDesc: '{ git-refs }' }]
    62                  --delete: [{ DynamicDesc: '{ git-refs }' }]
    63              }
    64          }]
    65  
    66          checkout: [{
    67              DynamicDesc: '{ git-refs }'
    68              Flags: [ -b ]
    69          }]
    70  
    71          config: [{
    72              DynamicDesc: '{
    73                  # `git config` flags and associated descriptions
    74                  git config ? tabulate --split-comma --map --key-inc-hint
    75              }'
    76          }]
    77  
    78          commit: [{
    79              Flags: [ -a, -m, --amend ]
    80              FlagValues: {
    81                  --amend: [{ AnyValue: true }]
    82              }
    83              AllowMultiple: true
    84              AllowAny: true
    85          }]
    86  
    87          diff: [{
    88              AllowMultiple: true
    89              Dynamic: '{
    90                  git -c color.ui=no status -s -> [:1]
    91              }'
    92          }]
    93  
    94          init: [{
    95              Flags: [--bare]
    96          }]
    97  
    98          merge: [{
    99              DynamicDesc: '{ git-refs }'
   100          }]
   101  
   102          mv: [{ 
   103              IncFiles: true
   104          }]
   105  
   106          push: [{
   107              Flags: [--tags]
   108          }]
   109  
   110          rm: [{
   111              IncFiles:      true
   112              AllowMultiple: true
   113          }]
   114  
   115          "": [{
   116              DynamicPreview: '{
   117                  exec git --help $1
   118              }'
   119              DynamicDesc: '{
   120                  exec git --help $1 -> man-get-flags -d
   121              }'
   122              AllowMultiple: true
   123              AllowAny: true
   124          }]
   125      }
   126  }]