-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fish shell completions support (#538)
Co-authored-by: Alexandre Archambault <[email protected]>
- Loading branch information
1 parent
993ac30
commit d753d92
Showing
5 changed files
with
81 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/shared/src/main/scala/caseapp/core/complete/Fish.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package caseapp.core.complete | ||
|
||
object Fish { | ||
|
||
val shellName: String = | ||
"fish" | ||
val id: String = | ||
s"$shellName-v1" | ||
|
||
def script(progName: String): String = | ||
s""" | ||
complete $progName -a '($progName complete $id (math 1 + (count (__fish_print_cmd_args))) (__fish_print_cmd_args))' | ||
|""".stripMargin | ||
|
||
private def escape(s: String): String = | ||
s.replace("\t", " ").linesIterator.find(_ => true).getOrElse("") | ||
def print(items: Seq[CompletionItem]): String = { | ||
val newLine = System.lineSeparator() | ||
val b = new StringBuilder | ||
for (item <- items; value <- item.values) { | ||
b.append(escape(value)) | ||
for (desc <- item.description) { | ||
b.append("\t") | ||
b.append(escape(desc)) | ||
} | ||
b.append(newLine) | ||
} | ||
b.result() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters