<?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: Boris Sh.</title>
    <description>The latest articles on DEV Community by Boris Sh. (@doker78).</description>
    <link>https://dev.to/doker78</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%2Fuser%2Fprofile_image%2F1131674%2Ff72f3efc-2ddd-4a4f-b929-01936f1ec6ac.gif</url>
      <title>DEV Community: Boris Sh.</title>
      <link>https://dev.to/doker78</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/doker78"/>
    <language>en</language>
    <item>
      <title>Bash Completion for kubectl</title>
      <dc:creator>Boris Sh.</dc:creator>
      <pubDate>Sun, 06 Aug 2023 11:00:00 +0000</pubDate>
      <link>https://dev.to/doker78/bash-completion-36ca</link>
      <guid>https://dev.to/doker78/bash-completion-36ca</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Bash is an &lt;code&gt;sh-compatible&lt;/code&gt; command language interpreter that executes commands read from the standard input or from a file. &lt;br&gt;
Bash can run most shell scripts without modification. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;bash-completion&lt;/code&gt; is a collection of shell functions that take advantage of the programmable completion feature of bash on Ubuntu Linux.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to add bash auto completion in Ubuntu Linux&lt;/strong&gt;&lt;br&gt;
The procedure is as follows to add &lt;code&gt;bash completion&lt;/code&gt; in &lt;code&gt;Ubuntu&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Open the terminal &lt;br&gt;
Refresh package database on &lt;code&gt;Ubuntu&lt;/code&gt; by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get info about the &lt;code&gt;bash-completion&lt;/code&gt; package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt info bash-completion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install &lt;code&gt;bash-completion&lt;/code&gt; package on &lt;code&gt;Ubuntu&lt;/code&gt; by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install bash-completion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Log out and log in to verify that &lt;code&gt;bash auto completion&lt;/code&gt; in &lt;code&gt;Ubuntu Linux&lt;/code&gt; working properly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to test programmable completion for Bash&lt;/strong&gt;&lt;br&gt;
Installer placed a shell script called &lt;code&gt;/etc/profile.d/bash_completion.sh&lt;/code&gt;. &lt;br&gt;
You can view it with help of cat command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat /etc/profile.d/bash_completion.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add &lt;code&gt;/etc/profile.d/bash_completion.sh&lt;/code&gt; to your &lt;code&gt;~/.bashrc&lt;/code&gt; file as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## source it from ~/.bashrc or ~/.bash_profile ##
echo "source /etc/profile.d/bash_completion.sh" &amp;gt;&amp;gt; ~/.bashrc

## Another example Check and load it from ~/.bashrc or ~/.bash_profile ##
grep -wq '^source /etc/profile.d/bash_completion.sh' ~/.bashrc || echo 'source /etc/profile.d/bash_completion.sh'&amp;gt;&amp;gt;~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will recommend after reading this post read the bash man page using the &lt;code&gt;man&lt;/code&gt; command or &lt;code&gt;help&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;man bash
help complete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Enable Kubectl Bash Completion
&lt;/h2&gt;

&lt;p&gt;The bash completion script of kubectl can be generated with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl completion bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first way can be achieved through the adding &lt;code&gt;~/.bashrc&lt;/code&gt;:&lt;br&gt;
Type the command in your command line tool, reload the bash shell and you are done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo ‘source &amp;lt;(kubectl completion bash)’ &amp;gt;&amp;gt;~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0scSD0KB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmqx2753u625b01c8y8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0scSD0KB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmqx2753u625b01c8y8v.png" alt="First - User way" width="725" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second way is to adding access the system&lt;br&gt;
In this mode, type command in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl completion bash | sudo tee /etc/bash_completion.d /kubectl &amp;gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SVhSfZCh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blqvxdchkje1cacr4pow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SVhSfZCh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blqvxdchkje1cacr4pow.png" alt="Second System way" width="729" height="79"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good Luck&lt;/p&gt;

</description>
      <category>bash</category>
      <category>ubuntu</category>
      <category>completion</category>
    </item>
  </channel>
</rss>
