<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: EcoLogic</title>
    <description>The latest articles on DEV Community by EcoLogic (@ecologic).</description>
    <link>https://dev.to/ecologic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F733%2F434c65fa-f905-4ef8-9652-a945d5f449ce.png</url>
      <title>DEV Community: EcoLogic</title>
      <link>https://dev.to/ecologic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ecologic"/>
    <language>en</language>
    <item>
      <title>Passing a parameter to a zsh keyboard-shortcut</title>
      <dc:creator>riscie</dc:creator>
      <pubDate>Fri, 17 May 2019 09:25:02 +0000</pubDate>
      <link>https://dev.to/ecologic/passing-a-parameter-to-a-zsh-keyboard-shortcut-1877</link>
      <guid>https://dev.to/ecologic/passing-a-parameter-to-a-zsh-keyboard-shortcut-1877</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;This post follows up on my previous post &lt;a href="https://dev.to/ecologic/using-keyboard-shortcuts-with-zsh-16b"&gt;Using keyboard-shortcuts with zsh&lt;/a&gt;. As promised I will show how we can pass an argument / string to a zsh keyboard-shortcut. &lt;/p&gt;

&lt;p&gt;We could for example use this option to create git feature branches by doing:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[typing the name of the branch] --&amp;gt; [keyboard-shortcut] --&amp;gt; [done]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0s0t3tkwq4odk5yfbjg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0s0t3tkwq4odk5yfbjg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Show me the code!
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# create a feature branch with &amp;lt;name&amp;gt; and then ctrl-g+f&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;featbranch&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;branch_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$BUFFER&lt;/span&gt;
    zle backward-kill-line
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"git checkout -b feat/&lt;/span&gt;&lt;span class="nv"&gt;$branch_name&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; &lt;span class="s2"&gt;"feat/&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;branch_name&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    zle reset-prompt
    zle redisplay
&lt;span class="o"&gt;}&lt;/span&gt;
zle &lt;span class="nt"&gt;-N&lt;/span&gt; featbranch
bindkey &lt;span class="s1"&gt;'^gf'&lt;/span&gt; featbranch


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A bit longer than our previous widget. Let's break it down line by line:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Another awesome comment&lt;/li&gt;
&lt;li&gt;The function which will be executed by our keystroke:&lt;/li&gt;
&lt;li&gt;Save the current terminal-line into a variable&lt;/li&gt;
&lt;li&gt;Clear the current line&lt;/li&gt;
&lt;li&gt;Display the full command we like to execute&lt;/li&gt;
&lt;li&gt;Execute the command&lt;/li&gt;
&lt;li&gt;Reset the prompt. (Useful if we display branch-information in our promt)&lt;/li&gt;
&lt;li&gt;Redisplay our prompt.&lt;/li&gt;
&lt;li&gt;Again we define a widget that points to the function&lt;/li&gt;
&lt;li&gt;And bind our key-combination to the widget&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So there we have it. Let me know if it works for you!&lt;/p&gt;

&lt;h2&gt;
  
  
  ❤️ Let's connect!
&lt;/h2&gt;

&lt;p&gt;I would love to grow my network with other tech enthusiasts. Let's connect here or over on twitter! &lt;a href="https://twitter.com/langhard" rel="noopener noreferrer"&gt;👋 @langhard&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://zsh.sourceforge.net/Guide/zshguide04.html" rel="noopener noreferrer"&gt;A User's Guide to the Z-Shell&lt;/a&gt;&lt;/p&gt;

</description>
      <category>zsh</category>
      <category>linux</category>
      <category>terminal</category>
      <category>shortcuts</category>
    </item>
    <item>
      <title>What are your five most used terminal commands?</title>
      <dc:creator>riscie</dc:creator>
      <pubDate>Wed, 15 May 2019 12:59:49 +0000</pubDate>
      <link>https://dev.to/ecologic/what-are-your-five-most-used-terminal-commands-1hmd</link>
      <guid>https://dev.to/ecologic/what-are-your-five-most-used-terminal-commands-1hmd</guid>
      <description>&lt;p&gt;&lt;strong&gt;I start:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     1  1874  18.3942%     git
     2  709   6.95917%     sudo
     3  622   6.10522%     cd
     4  565   5.54574%     kubectl
     5  480   4.71143%     docker
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I found this nice gem in &lt;a href="https://github.com/trimstray/the-book-of-secret-knowledge/blob/master/README.md#list-of-commands-you-use-most-often"&gt;the-book-of-secret-knowledge&lt;/a&gt;. (A good link for any terminal user. Have a look!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;show your top 5 most used commands including their usage %&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;history&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}'&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"./"&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
column &lt;span class="nt"&gt;-c3&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-nr&lt;/span&gt; | &lt;span class="nb"&gt;nl&lt;/span&gt; |  &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(the original was slightly modified to only show the top 5, instead of 20)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I tought it would be fun to share our most used commands here. Show me yours! ;)&lt;/p&gt;

&lt;h2&gt;
  
  
  ❤️ Let's connect!
&lt;/h2&gt;

&lt;p&gt;I would love to grow my network with other tech enthusiasts. Let's connect here or over on twitter! &lt;a href="https://twitter.com/langhard"&gt;👋 @langhard&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Heads up
&lt;/h2&gt;

&lt;p&gt;I mean I almost don't need to say this, but: &lt;strong&gt;Please have a close look at your commands before you share them, don't share private information!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>terminal</category>
      <category>unix</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Using keyboard-shortcuts with zsh</title>
      <dc:creator>riscie</dc:creator>
      <pubDate>Tue, 14 May 2019 08:35:18 +0000</pubDate>
      <link>https://dev.to/ecologic/using-keyboard-shortcuts-with-zsh-16b</link>
      <guid>https://dev.to/ecologic/using-keyboard-shortcuts-with-zsh-16b</guid>
      <description>&lt;p&gt;Are you a zsh user? Do you like to tweak your shell to the maxium in order to gain a bit of time here or there? You might be in the right place here.&lt;/p&gt;

&lt;p&gt;This post will show you how to use keyboard shortcuts within zsh to run common commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7f2slxhq0mrlsdnsu0c.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7f2slxhq0mrlsdnsu0c.gif" alt="gif showing how to use the shortcut to run git pull" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  git pull using a keyboard shortcut
&lt;/h2&gt;

&lt;p&gt;In this example we want to run &lt;code&gt;git pull&lt;/code&gt; with the shortcut &lt;code&gt;ctrl-g+p&lt;/code&gt; (meaning &lt;code&gt;ctrl-g&lt;/code&gt; - releasing &lt;code&gt;g&lt;/code&gt; - pressing &lt;code&gt;p&lt;/code&gt;) as seen in the gif above.&lt;/p&gt;

&lt;p&gt;We define our shortcuts in the zsh ressource file. It's normally called &lt;code&gt;.zshrc&lt;/code&gt; and we find it within our home directory. I use visual studio code to edit the file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;code ~/.zshrc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following content to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# git pull (ctrl-g+p)&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;gitpull&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"git pull"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; git pull&lt;span class="p"&gt;;&lt;/span&gt; zle reset-prompt&lt;span class="p"&gt;;&lt;/span&gt; zle redisplay&lt;span class="o"&gt;}&lt;/span&gt;
zle &lt;span class="nt"&gt;-N&lt;/span&gt; gitpull
bindkey &lt;span class="s1"&gt;'^gp'&lt;/span&gt; gitpull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Lets break it down line-by-line&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A nice comment&lt;/li&gt;
&lt;li&gt;We define the function gitpull which we use for our keybinding later. The function does:

&lt;ol&gt;
&lt;li&gt;Write out the command we send. (I like this over having an empty screen doing something)&lt;/li&gt;
&lt;li&gt;Runs &lt;code&gt;git pull&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Resets our prompt. (This is useful, if we have git information in our prompt, as they are not updated if we don't use &lt;code&gt;reset-prompt&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Redisplays our prompt&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;We define a widget that points to the function&lt;/li&gt;
&lt;li&gt;We bind our key-combination to the widget&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it. Let me know if it works for you. If there is some interest in this kind of stuff, I could follow up with an example of how to pass an argument to a keyboard shortcut. I for example use this option to create feature branches by doing:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;typing the name of the feature branch --&amp;gt; ctrl-g+f&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1f439221skirs681667.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1f439221skirs681667.gif" alt="gif showing how to use the shortcut to create a feature branch" width="1519" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;Some more shortcut definition examples also using &lt;code&gt;alt&lt;/code&gt; as the modifier to get you started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'^g'   # ctrl-g
'^gp'  # ctrl-g and then p (as shown in the example)
'^[x'  # alt-x
'^[xc' # alt-x and then c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ❤️ Let's connect!
&lt;/h2&gt;

&lt;p&gt;I would love to grow my network with other tech enthusiasts. Let's connect here or over on twitter! &lt;a href="https://twitter.com/langhard"&gt;👋 @langhard&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://zsh.sourceforge.net/Guide/zshguide04.html"&gt;A User's Guide to the Z-Shell&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Update
&lt;/h2&gt;

&lt;p&gt;Part 2 - &lt;a href="https://dev.to/ecologic/passing-a-parameter-to-a-zsh-keyboard-shortcut-1877"&gt;Passing a parameter to a zsh keyboard-shortcut&lt;/a&gt; - is now online.&lt;/p&gt;

</description>
      <category>zsh</category>
      <category>shortcuts</category>
      <category>terminal</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
