<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Command-Line on CodeGoalie</title><link>https://codegoalie.com/categories/command-line/</link><description>Recent content in Command-Line on CodeGoalie</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 04 Jan 2023 14:35:12 -0500</lastBuildDate><atom:link href="https://codegoalie.com/categories/command-line/index.xml" rel="self" type="application/rss+xml"/><item><title>One-liner to copy a Github PR link from the terminal</title><link>https://codegoalie.com/posts/copy-pr-link/</link><pubDate>Wed, 04 Jan 2023 14:35:12 -0500</pubDate><guid>https://codegoalie.com/posts/copy-pr-link/</guid><description>&lt;p>Here&amp;rsquo;s a super quick one-liner to copy the current branch&amp;rsquo;s PR URL to your
clipboard (for posting into Slack, tickets, etc.)&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ gh pr view --json url --jq .url | &amp;lt;pbcopy | xclip -sel c&amp;gt;
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Remember to replace the copy command with your platform&amp;rsquo;s specific command.&lt;/p>
&lt;p>This would also make a good shell alias.&lt;/p>
&lt;p>Also, also, I might try setting up &lt;a href="https://github.com/Slackadays/Clipboard">Clipboard&lt;/a> for multi-platform goodness.&lt;/p>
&lt;p>Happy PR-ing!&lt;/p>
&lt;p>&amp;ndash; Chris&lt;/p></description></item><item><title>Useful command line expansions</title><link>https://codegoalie.com/posts/2014-08-17-useful-command-line-expansions/</link><pubDate>Mon, 25 Aug 2014 00:00:00 +0000</pubDate><guid>https://codegoalie.com/posts/2014-08-17-useful-command-line-expansions/</guid><description>&lt;p>Here&amp;rsquo;s a quick trick I&amp;rsquo;ve been using for a while, but have found that not many
others know about it. It&amp;rsquo;s a way to grab the arguments from the last command you
executed. Command line expansion allows you to &lt;a href="http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html">do many
things&lt;/a>, but
today we&amp;rsquo;ll focus on just argument expansion.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;p>First to simply repeat the last command with &lt;code>!!&lt;/code>. This is most helpful when
needing to prefix a command; with something like &lt;code>sudo&lt;/code> or &lt;code>bundle exec&lt;/code>.&lt;/p>
&lt;pre>&lt;code>$ mv /really/long/path/with/more/dirs/file /another/deeply/nested/dir/structure
mv: cannot move `...' to `...': Permission denied
$ sudo !!
&lt;/code>&lt;/pre>&lt;p>Learn more about bang-bang on &lt;a href="https://sysadmincasts.com/episodes/32-cli-monday-history">episode 32 of sysadmin
casts&lt;/a>.&lt;/p>
&lt;p>Expanding on this concept, how about only part of the previous command? The
&lt;code>!$&lt;/code> history expansion expands to the last argument (or token) from the previous
command. Working off the previous example, if we now want to edit that freshly
moved file:&lt;/p>
&lt;pre>&lt;code>$ vim !$
&lt;/code>&lt;/pre>&lt;p>which expands to&lt;/p>
&lt;pre>&lt;code>$ vim /another/deeply/nested/dir/structure
&lt;/code>&lt;/pre>&lt;p>Quick and easy! There are many ways to use history expansion to get parts of the
previous (and others from history) command. &lt;code>!$&lt;/code> is by far the one I use the
most. You&amp;rsquo;ll do yourself a huge favor to commit that to muscle memory.&lt;/p>
&lt;p>To get an argument other than the last, you can use &lt;code>!:x&lt;/code> where &lt;code>x&lt;/code> is the (0
based) index of the arguemnt, or a range, or &lt;code>*&lt;/code> to get all the arguments.&lt;/p>
&lt;pre>&lt;code>$ vim /another/deeply/nested/dir/structure
$ git checkout -b features/laser-sharks
!:2 =&amp;gt; -b
!:0 =&amp;gt; git
!:$ =&amp;gt; features/laser-sharks
!:^ =&amp;gt; checkout
!:1-2 =&amp;gt; checkout -b
!:-2 =&amp;gt; git checkout -b
!:2-$ =&amp;gt; -b features/laser-sharks
!:* =&amp;gt; checkout -b features/laser-sharks
&lt;/code>&lt;/pre>&lt;blockquote>
&lt;p>ZSH power tip: Tapping &lt;code>tab&lt;/code> with any of these expansions in ZSH will expand
them inline to preview before executing.&lt;/p>
&lt;/blockquote>
&lt;p>Happy history-ing!&lt;/p>
&lt;p>&amp;ndash; Chris&lt;/p></description></item></channel></rss>