Skip to content

Commit 04182d6

Browse files
authored
Merge pull request #17 from til/use-completing-read
Use completing-read in interactive prompt for ruby version
2 parents 327f04a + 1f95a82 commit 04182d6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

chruby.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ ruby version, and the gem path"
164164
(defun chruby-use (ruby-version)
165165
"choose what ruby you want to activate"
166166
(interactive
167-
(let ((picked-ruby (read-string "Ruby version: ")))
167+
(let ((picked-ruby (completing-read "Ruby version: " (chruby--available-names))))
168168
(list picked-ruby)))
169169
(if (chruby-activate ruby-version)
170170
(message (concat "[chruby] using " ruby-version))
@@ -178,6 +178,10 @@ ruby version, and the gem path"
178178
(if version-file-path (chruby-use (chruby--read-version-from-file version-file-path))
179179
(message "[chruby] could not locate .ruby-version"))))
180180

181+
(defun chruby--available-names ()
182+
"list of available ruby names without path, higher versions sorted first"
183+
(reverse (mapcar 'chruby-util-basename (chruby-rubies))))
184+
181185
(defun chruby--replace-trailing-whitespace (text)
182186
(replace-regexp-in-string "[[:space:]]\\'" "" text))
183187

0 commit comments

Comments
 (0)