aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/scripts/find-php-class
blob: 3564f000ab4264bd2614d56addebb687e5861188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env -S scsh -e main -o srfi-1 -s
;; -*- mode: scheme; -*-
!#

(define (find-class class-name)
  (run/strings (find "." "("
                     -path "./cdk.out"
                     -o -path "./*/tmp"
                     -o -path "./*/node_modules"
                     -o -path "./*/.phpunit.cache"
                     -o -path "./*/storage"
                     -o -path "./.git"
                     -o -path "./data"
                     ")" -prune
                     -o -type f -name ,(string-append class-name ".php")
                     -exec grep "^namespace" "{}" ";")
               (> 2 "/dev/null")))


(define (main args)
  (let* ((class-name (cadr args))
         (file-names (find-class class-name)))
    (format #t "~s"
            (delete-duplicates
             (map (lambda (n)
                    (string-append
                     (match:substring
                      (regexp-search (rx "namespace " (submatch (+ any)) ";") n)
                      1)
                     "\\"
                     class-name))
                  file-names)))))