Premise

I would like to quckly jump to the entrypoint of a repository I have just downloaded.

Demonstration

asciinema recording

Repositories with lots of languages

asciinema recording

asciinema recording

Code

elisp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(defun open-main ()
  (interactive)
  (let ((found (fz (sn "open-main") nil nil nil nil t)))
    (if found
        ;; (find-file found)
        (let ((path (s-replace-regexp "^\\([^:]+\\).*" "\\1" found))
              (pos (s-replace-regexp "^[^:]+:\\([0-9]+\\):.*" "\\1" found)))
          (with-current-buffer (find-file path)
            (goto-byte (string-to-int pos))))
        ;; (etv found)
      )))

(define-key global-map (kbd "H-o") 'open-main)

shell

open-main

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
export TTY

# ( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

exec 0</dev/null

rg() {
    command rg --no-heading --line-buffered -b -g "$@"
}

{
    rg '**/*.py' '^def main\b'
    rg '**/*.{c,cc,cpp}' '\b main\(\b'
    rg '**/*.clj' 'defn -main\b'
    rg '**/*.hs' '^main :: IO\b'
    rg '**/*.go' '^func main\b'
    rg '**/*.rs' '^pub fn main\b'
} | sort-by-line-length.sh | sort-by-path-depth.sh | pavs

perl

sort-by-line-length.sh

1
2
3
4
5
#!/bin/bash
export TTY

# perl sort with custom comparator
perl -e 'print sort { length($a) <=> length($b) } <>'

sort-by-path-depth.sh

1
2
3
4
5
#!/bin/bash
export TTY

# perl sort with custom comparator
perl -e 'print sort { ($a =~ tr!/!!) <=> ($b =~ tr!/!!) } <>'