Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Aug 11, 2023
1 parent 20fe622 commit e90a209
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions flutter.el
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,20 @@ args."
(display-buffer buffer)))

(defun flutter-devices ()
"Return a list of devices in strings."
"Return an alist of devices in (name . ID) format."
(let* ((output (shell-command-to-string "flutter devices --machine"))
(vec (json-read-from-string output))
(matches))
(mapc (lambda (alist)
(let-alist alist
(push .id matches)))
vec)
(reverse matches)))
(vec (json-read-from-string output)))
(mapcar
(lambda (alist) (let-alist alist (cons .name .id)))
vec)))

;;;###autoload
(defun flutter-run-device (device-id)
"Start `flutter run` with DEVICE-ID."
(interactive
(list (completing-read
"Device ID: "
(lambda (string predicate action)
(if (eq action 'metadata)
`(metadata
(display-sort-function . ,#'identity))
(complete-with-action action (flutter-devices) string predicate))))))
(list (let* ((collection (flutter-devices))
(choice (completing-read "Device: " collection)))
(cdr (assoc choice collection)))))
(flutter-run (format "-d %s" device-id)))

;;;###autoload
Expand Down

0 comments on commit e90a209

Please sign in to comment.