Skip to content
Snippets Groups Projects
Select Git revision
  • 042bcdd8ed6cf4b8205aa864826174446700f6fd
  • master default protected
  • 9.0
  • 8.0
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • nt-tools
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
  • v8.0.1982
  • v8.0.1980
  • v8.0.1978
  • v8.0.1976
  • v8.0.1974
  • v8.0.1972
  • v8.0.1970
  • v8.0.1968
  • v8.0.1966
41 results

Ident.pmod

Blame
  • git-ls.scm 2.86 KiB
    #!/usr/bin/guile \
    -e main -s
    !#
    
    (use-modules (srfi srfi-1)
                 (srfi srfi-71)
                 (ice-9 ftw)
                 (ice-9 regex)
                 (ice-9 popen))
    
    
    (define cyan "0;36")
    (define normal "")
    (define error "1;31")
    
    (define* (ansi-escape color #:optional (port #f))
      (format port "\x1b[~am" color))
    
    (define dir-color
      (cond ((find (lambda (s) (string-match "^di=" s))
                    (string-split (or (getenv "LS_COLORS") "") #\:))
             => (lambda (s) (string-drop s 3)))
            (else "01;34")))
    
    
    (define-public (group list width)
      (unless (zero? (modulo (length list) width))
        (scm-error 'misc-error "group" "~a∤~a (~s)" `(,width ,(length list) ,list) '()))
      (let inner ((list list))
        (if (null? list)
            '()
            (let* ((row rest (split-at list width)))
              (cons row (inner rest))))))
    
    
    (define (main args)
    
      (define cols  (read (open-input-pipe "tput cols")))
      (define dir
        (if (< 1 (length args))
            (cadr args)
            "."))
    
      (define items
        (map
         (lambda (pair)
           (case (car pair)
             ((module) (cons cyan (cdr pair)))
             ((regular)
              (catch 'system-error
                (lambda ()
                  (case (stat:type (stat (string-append dir "/" (cdr pair))))
                    ((regular symlink block-special char-special fifo socket
                              unknown)
                     (cons normal (cdr pair)))
                    ((directory)
                     (cons dir-color (cdr pair)))))
                (const (cons error (cdr pair)))))))
         (map (lambda (file)
                (if (file-exists? (string-append dir "/" file "/.git"))
                    (cons 'module file)
                    (cons 'regular file)))
              (remove (lambda (filename)
                        (char=? #\. (string-ref filename 0)))
               (scandir dir)))))
    
      (let ()
        (define longest-string (apply max (map string-length (map cdr items))))
        (define items-per-line (floor (/ cols (+ 1 longest-string))))
    
        (let ((head tail-line (split-at items
                                        (- (length items)
                                           (modulo (length items) items-per-line)))))
          (for-each (lambda (group)
                      (for-each (lambda (item)
                                  (format #t "~a~a~a"
                                          (ansi-escape (car item))
                                          (string-pad-right (cdr item) (1+ longest-string))
                                          (ansi-escape normal)))
                                group)
                      (newline))
                    (group head items-per-line))
          (for-each (lambda (item)
                      (format #t "~a~a~a"
                              (ansi-escape (car item))
                              (string-pad-right (cdr item) (1+ longest-string))
                              (ansi-escape normal)))
                    tail-line)
          (unless (null? tail-line)
            (newline)))))