﻿{"id":17785,"date":"2022-08-30T08:25:41","date_gmt":"2022-08-30T00:25:41","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=17785"},"modified":"2022-08-30T15:04:31","modified_gmt":"2022-08-30T07:04:31","slug":"gum-linux-shell-tool","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/gum-linux-shell-tool.html","title":{"rendered":"Gum &#8211; Linux \u4e2d\u8ff7\u4eba\u7684 Shell \u811a\u672c\u5de5\u5177"},"content":{"rendered":"<p>\u5982\u679c\u60a8\u662f Linux \u64cd\u4f5c\u7cfb\u7edf\u7231\u597d\u8005\u6216\u6b63\u5728\u5c06\u81ea\u5df1\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u7231\u597d\u8005\uff0c\u90a3\u4e48\u4e0e shell \u811a\u672c\u4ea4\u53c9\u8def\u5f84\u662f\u5b8c\u5168\u4e0d\u53ef\u907f\u514d\u7684\u3002\u6839\u636e\u5b9a\u4e49\uff0cshell \u811a\u672c\u662f\u8bbe\u8ba1\u7528\u4e8e\u5728 Unix\/Linux shell \u73af\u5883\u4e2d\u6267\u884c\u7684\u7a0b\u5e8f\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u547d\u4ee4\u884c\u89e3\u91ca\u5668 (\u00a0<strong>shell ) \u4e0e\u8bf8\u5982<\/strong>\u6253\u5370\u6587\u672c\u3001\u7a0b\u5e8f\u6267\u884c\u548c\u6587\u4ef6\u64cd\u4f5c\u7b49\u811a\u672c\u64cd\u4f5c\u76f8\u5173\u8054\u3002\u6d41\u884c\u7684 Unix\/Linux shell \u73af\u5883\u7684\u793a\u4f8b\u5305\u62ec GNU Bourne-Again Shell\u3001Bourne Shell\u3001Korn Shell \u548c C Shell\u3002<\/p>\n<p>\u5728 Linux \u64cd\u4f5c\u7cfb\u7edf\u73af\u5883\u4e2d\u8fd0\u884c\u7684 Shell \u811a\u672c\u5177\u6709<code>.sh<\/code>\u6587\u4ef6\u6269\u5c55\u540d\u3002\u8003\u8651\u6267\u884c\u4ee5\u4e0b shell \u811a\u672c\u6587\u4ef6\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ .\/linuxmi.sh<\/code><\/pre>\n<figure id=\"attachment_5928\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5928\"><figcaption id=\"caption-attachment-5928\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17786\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/1-6.png\" alt=\"\" width=\"1038\" height=\"317\" \/><br \/>\n\u5728 Linux \u4e2d\u8fd0\u884c Shell \u811a\u672c<\/figcaption><\/figure>\n<p>\u4e0a\u8ff0 shell \u811a\u672c\u7684\u6267\u884c\u662f\u975e\u5e38\u7b80\u5355\u57fa\u672c\u7684\u3002\u5982\u679c\u60a8\u4ecb\u610f shell \u811a\u672c\u7684\u5916\u89c2\uff0c\u90a3\u4e48\u672c\u6587\u9002\u5408\u60a8\u3002\u5b83\u5c06\u5f15\u5bfc\u6211\u4eec\u5b8c\u6210\u5b89\u88c5\uff0c\u4f7f\u7528<strong>Gum<\/strong>\u521b\u5efa\u8ff7\u4eba\u7684 shell \u811a\u672c\u3002<\/p>\n<p><a title=\"Gum - \u8ff7\u4eba\u7684 Shell \u811a\u672c\u5de5\u5177\" href=\"https:\/\/github.com\/charmbracelet\/gum\" target=\"_blank\" rel=\"nofollow noopener\">Gum<\/a>\u9884\u5148\u6253\u5305\u4e86\u5373\u7528\u578b\u548c\u9ad8\u5ea6\u53ef\u914d\u7f6e\u7684\u5b9e\u7528\u7a0b\u5e8f\uff0c\u4f7f Linux \u7528\u6237\u80fd\u591f\u5b9e\u73b0\u51e0\u884c\u4ee3\u7801\u6765\u6210\u529f\u5730\u63d0\u51fa\u9002\u7528\u7684 shell \u811a\u672c\u548c\u70b9\u6587\u4ef6\u522b\u540d\u3002<\/p>\n<h3>\u5728 Linux \u4e2d\u5b89\u88c5 Gum<\/h3>\n<p>\u5728\u6211\u4eec\u770b\u5230<strong>Gum<\/strong>\u5de5\u5177\u80fd\u591f\u5b9e\u73b0\u4ec0\u4e48\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5b83\u5b89\u88c5\u5728\u6211\u4eec\u7684 Linux \u64cd\u4f5c\u7cfb\u7edf\u53d1\u884c\u7248\u4e0a\u3002\u56e0\u4e3a\u5b83\u4e0d\u80fd\u5728\u6240\u6709\u4e3b\u8981\u7684 Linux \u5305\u7ba1\u7406\u5668\u4e2d\u8bbf\u95ee\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528 Homebrew \u5305\u7ba1\u7406\u5668\uff08\u53ef\u5b89\u88c5\u5728\u6240\u6709\u4e3b\u8981\u7684 Linux \u53d1\u884c\u7248\u4e0a\uff09\u3002\u5982\u679c\u60a8\u5c1a\u672a\u5728 Linux \u53d1\u884c\u7248\u4e0a\u5b89\u88c5 Homebrew\uff0c\u8bf7\u53c2\u9605\u6211\u4eec\u5728\u5176\u4e0a\u7f16\u5199\u7684 Homebrew \u5b89\u88c5\u6587\u7ae0\u3002<\/p>\n<p>\u94fe\u63a5\uff1a\u5728 Linux \u4e0a\u5b89\u88c5\u548c\u4f7f\u7528 Homebrew \u5305\u7ba1\u7406\u5668 <a href=\"https:\/\/www.linuxmi.com\/linux-homebrew-brew.html\">https:\/\/www.linuxmi.com\/linux-homebrew-brew.html<\/a><\/p>\n<p>\u5b89\u88c5\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<strong>Homebrew<\/strong>\u5b89\u88c5<b> Gum <\/b>\u5de5\u5177\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi \/home\/linuxmi\/www.linuxmi.com                                     \r\n\u26a1 brew install gum<\/code><\/pre>\n<figure id=\"attachment_5929\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5929\"><figcaption id=\"caption-attachment-5929\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17789\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/2-5.png\" alt=\"\" width=\"1038\" height=\"695\" \/><br \/>\n\u5728 Linux \u4e2d\u5b89\u88c5 Gum<\/figcaption><\/figure>\n<p>\u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728<strong>Debian\/Ubuntu\u53d1\u884c\u7248\u4e0a\u5b89\u88c5<\/strong><strong>Gum \u3002<\/strong><\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ echo 'deb [trusted=yes] https:\/\/repo.charm.sh\/apt\/ \/' | sudo tee \/etc\/apt\/sources.list.d\/charm.list\r\n$ sudo apt update &amp;&amp; sudo apt install gum<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17790\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/gum.png\" alt=\"\" width=\"1038\" height=\"587\" \/><\/p>\n<p>\u5728 Arch \u548c Manjaro Linux \u4e0a\uff0c\u4f7f\u7528\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ sudo pacman -S gum<\/code><\/pre>\n<h3>Linux \u4e2d\u7684 Gum \u57fa\u672c\u7528\u6cd5<\/h3>\n<p>\u51e0\u4e2a\u6709\u7528\u7684\u547d\u4ee4\u4e0e<strong>Gum<\/strong>\u76f8\u5173\u8054\uff1a<\/p>\n<h4>\u4ece\u9009\u9879\u5217\u8868\u4e2d\u9009\u62e9<\/h4>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u53ef\u4ee5\u4ece\u51e0\u4e2a\u5217\u51fa\u7684\u9009\u9879\u4e2d\u9009\u62e9\u4e00\u4e2a\u9009\u9879\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ echo \"\u5728\u4efb\u610f\u4e00\u5f20\u724c\u4e0a\u53d6\u724c...\" CARD=$(gum choose --height 15 {{A,K,Q,J},{10..2}}\" \"{\u2660,\u2665,\u2663,\u2666})<\/code><\/pre>\n<figure id=\"attachment_5930\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5930\"><figcaption id=\"caption-attachment-5930\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17791\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/3-4.png\" alt=\"\" width=\"1038\" height=\"722\" \/><br \/>\n\u9009\u62e9\u5217\u8868<\/figcaption><\/figure>\n<p>\u4e0a\u9762\u7684\u547d\u4ee4\u6267\u884c\u5e94\u8be5\u53ef\u4ee5\u6307\u51fa\u7528\u6237\u7684\u9009\u62e9\u3002<\/p>\n<h4>\u8f93\u5165<\/h4>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u7528\u6237\u5728\u7ec8\u7aef\u4e0a\u63d0\u4f9b\u6807\u51c6\u8f93\u5165\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ gum input &gt; linuxmi.txt<\/code><\/pre>\n<figure id=\"attachment_5931\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5931\"><figcaption id=\"caption-attachment-5931\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17792\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/4-4.png\" alt=\"\" width=\"1038\" height=\"263\" \/><br \/>\nShell \u6807\u51c6\u8f93\u5165<\/figcaption><\/figure>\n<p>\u5982\u679c\u60a8\u9700\u8981\u654f\u611f\u7684\u8f93\u5165\uff0c\u8bf7\u4f7f\u7528\u8be5<code>--password<\/code>\u6807\u5fd7\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ gum input --password &gt; linuxmi.txt<\/code><\/pre>\n<h4 style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17793\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/5-5.png\" alt=\"\" width=\"1038\" height=\"317\" \/><\/h4>\n<h4>\u5199<\/h4>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u63d0\u4f9b\u591a\u884c\u8f93\u5165\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ gum write &gt; linuxmi.txt<\/code><\/pre>\n<figure id=\"attachment_5932\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5932\"><figcaption id=\"caption-attachment-5932\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17794\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/6-5.png\" alt=\"\" width=\"1038\" height=\"398\" \/><br \/>\nLinux \u591a\u884c\u8f93\u5165<\/figcaption><\/figure>\n<h4>\u7b5b\u9009<\/h4>\n<p>\u53ef\u4ee5\u901a\u8fc7\u6a21\u7cca\u5339\u914d\u8fc7\u6ee4\u503c\u5217\u8868\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ echo red &gt;&gt; colors.txt\r\n$ echo green &gt;&gt; colors.txt\r\n$ echo blue &gt;&gt; colors.txt\r\n$ cat colors.txt | gum filter &gt; selector.txt<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17795\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/7-4.png\" alt=\"\" width=\"1038\" height=\"533\" \/><\/p>\n<p>\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u5c06\u5bfc\u81f4\u4ee5\u4e0b\u5c4f\u5e55\u622a\u56fe\u663e\u793a\uff1a<\/p>\n<figure id=\"attachment_5933\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5933\"><figcaption id=\"caption-attachment-5933\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17796\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/8-2.png\" alt=\"\" width=\"1038\" height=\"263\" \/>\u7b5b\u9009\u503c\u5217\u8868<\/figcaption><\/figure>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u952e\u5165\u5173\u952e\u5b57\u6765\u8fc7\u6ee4\u5217\u8868\u3002<\/p>\n<h4>\u786e\u8ba4<\/h4>\n<p>\u53ef\u4ee5\u5728\u6267\u884c\u4e4b\u524d\u786e\u8ba4\u7528\u6237\u7684\u64cd\u4f5c\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ gum confirm &amp;&amp; rm new.txt || echo \"\u65e0\u6cd5\u5b9a\u4f4d\u6587\u4ef6\"<\/code><\/pre>\n<figure id=\"attachment_5934\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5934\"><figcaption id=\"caption-attachment-5934\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17797\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/9-2.png\" alt=\"\" width=\"1038\" height=\"290\" \/><br \/>\n\u786e\u8ba4\u7528\u6237\u64cd\u4f5c<\/figcaption><\/figure>\n<h4>spin<\/h4>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u5728\u547d\u4ee4\/\u811a\u672c\u6267\u884c\u65f6\u663e\u793aspinner\uff0c\u540c\u65f6\u901a\u8fc7<strong>sleep<\/strong>\u547d\u4ee4\u53c2\u6570\u6307\u5b9a spin \u7684\u6301\u7eed\u65f6\u95f4\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ gum spin --spinner dot --title \"\u8bbf\u95eeLinux\u8ff7\u7f51\u7ad9www.linuxmi.com ...\" -- sleep 10<\/code><\/pre>\n<figure id=\"attachment_5935\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5935\"><figcaption id=\"caption-attachment-5935\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17798\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/10-2.png\" alt=\"\" width=\"1038\" height=\"317\" \/><br \/>\n\u663e\u793a spinner<\/figcaption><\/figure>\n<p>\u5982\u679c\u60a8\u8981\u521b\u5efa\u4e00\u4e2a shell \u811a\u672c\uff0c\u60a8\u7684\u811a\u672c\u6587\u4ef6\u5e94\u8be5\u6709\u4ee5\u4e0b\u6807\u9898\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">#!\/bin\/sh<\/code><\/pre>\n<figure id=\"attachment_5936\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5936\"><figcaption id=\"caption-attachment-5936\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17799\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/11-2.png\" alt=\"\" width=\"1038\" height=\"290\" \/><br \/>\n\u5728 Linux \u4e2d\u521b\u5efa Shell \u811a\u672c<\/figcaption><\/figure>\n<p>\u4f7f\u811a\u672c\u53ef\u6267\u884c\u5e76\u8fd0\u884c\u5b83\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ chmod +x linuxmi.sh\r\n$ .\/linuxmi.sh <\/code><\/pre>\n<figure id=\"attachment_5937\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-5937\"><figcaption id=\"caption-attachment-5937\" class=\"wp-caption-text\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17800\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/08\/12-1.png\" alt=\"\" width=\"1038\" height=\"425\" \/><br \/>\n\u5728 Linux \u4e2d\u6267\u884c\u811a\u672c<\/figcaption><\/figure>\n<p>\u66f4\u591a<strong>gum<\/strong>\u4f7f\u7528\u53c2\u8003\u53ef\u4ee5\u5728\u5176\u7528\u6237\u624b\u518c\u4e2d\u627e\u5230\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ gum -h <\/code><\/pre>\n<p>\u8981\u5f15\u7528\u7c7b\u4f3c\u547d\u4ee4\u683c\u5f0f\u7684\u7528\u6cd5\uff0c\u8bf7\u8fd0\u884c\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">$ gum format -h <\/code><\/pre>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u6307\u5357\u4f7f\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5f00\u59cb\u548c\u521b\u5efa\u8ff7\u4eba\u7684 shell \u811a\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u60a8\u662f Linux \u64cd\u4f5c\u7cfb\u7edf\u7231\u597d\u8005\u6216\u6b63\u5728\u5c06\u81ea\u5df1\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u7231\u597d\u8005\uff0c\u90a3\u4e48\u4e0e shell \u811a\u672c\u4ea4\u53c9\u8def\u5f84\u662f &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[1211,154],"class_list":["post-17785","post","type-post","status-publish","format-standard","hentry","category-linux","tag-gum","tag-shell"],"aioseo_notices":[],"views":1827,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/17785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=17785"}],"version-history":[{"count":5,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/17785\/revisions"}],"predecessor-version":[{"id":17803,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/17785\/revisions\/17803"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=17785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=17785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=17785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}