I think ... - Ubuntuhttps://blog.kmonsoor.com/2021-03-31T00:00:00+06:00Pimping up My Linux Terminal2021-03-31T00:00:00+06:002021-03-31T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2021-03-31:/pimp-up-my-terminal/<p>How do I pimp up my Linux terminal? A quick trip through Zsh, Oh-my-zsh, and other power tools to make the command-line-based workflow smooth and&nbsp;cool.</p><p>The purpose of this post is to be my quick, copy-paste source of the commands that I use to set up my terminal on a new *nix system. However, if someone else finds it useful, that&rsquo;d be some cherries on&nbsp;top.</p> <p>This command prompt in the below image is the end&nbsp;goal.</p> <p><img alt="The end goal of this post" src="https://i.imgur.com/oZahIog.png"></p> <p>Assuming, I&rsquo;m on a standard pc/server with Ubuntu Linux and I have <span class="caps">CLI</span> access with <code>sudo</code>. For other Linux distros or <em>MacOS</em>, some commands might be slightly&nbsp;different.</p> <h2 id="step-1-confirm-that-zsh-is-up-to-date">Step-1: Confirm that Zsh is up-to-date<a class="headerlink" href="#step-1-confirm-that-zsh-is-up-to-date" title="Permanent link">&para;</a></h2> <p>While on most of the Linux systems Zsh is present by default, on others that&rsquo;s not the case. So, let&rsquo;s make sure about&nbsp;it.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo apt install zsh </code></pre></div> <p>Confirm the version. <code>Oh-my-zsh</code> recommends Zsh to be <code>5.0.8</code> or&nbsp;higher.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>zsh --version <span class="linenos" data-linenos="2 "></span><span class="go">zsh 5.8 (x86_64-ubuntu-linux-gnu)</span> </code></pre></div> <p>Also, you gotta make sure that <code>git</code> (recommended v2.4.11 or higher) is also installed on the&nbsp;system.</p> <h2 id="step-2-install-oh-my-zsh-the-fun-configuration-framework">Step-2: Install Oh-my-zsh, the fun &ldquo;configuration&rdquo; framework<a class="headerlink" href="#step-2-install-oh-my-zsh-the-fun-configuration-framework" title="Permanent link">&para;</a></h2> <p>Install directly from the&nbsp;source.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sh -c <span class="s2">&quot;</span><span class="k">$(</span>curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh<span class="k">)</span><span class="s2">&quot;</span> </code></pre></div> <p>In the last step of this installation, it will ask to set Zsh as <span class="caps">THE</span> shell. Go&nbsp;ahead.</p> <p>Now we have the default prompt from <code>Oh-my-zsh</code>. </p> <p><img alt="After successful installation of Oh-my-zsh" src="https://i.imgur.com/HOVqqvi.png"></p> <p>Now, let&rsquo;s pimp up the prompt. Shall&nbsp;we?</p> <h2 id="step-3-install-powerlevel10k-a-powerful-prompt-theme">Step-3: Install <code>powerlevel10k</code>, a powerful prompt theme<a class="headerlink" href="#step-3-install-powerlevel10k-a-powerful-prompt-theme" title="Permanent link">&para;</a></h2> <p>I love the powerful Zsh theme <code>powerlevel10k</code>. More on <a href="https://github.com/romkatv/powerlevel10k#features">why this theme</a> is&nbsp;awesome.</p> <p>Let&rsquo;s install it on top of <code>oh-my-zsh</code>.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>git clone --depth<span class="o">=</span><span class="m">1</span> <span class="se">\</span> <span class="linenos" data-linenos="2 "></span> https://github.com/romkatv/powerlevel10k.git <span class="se">\</span> <span class="linenos" data-linenos="3 "></span><span class="gp"> $</span><span class="o">{</span>ZSH_CUSTOM:-<span class="nv">$HOME</span>/.oh-my-zsh/custom<span class="o">}</span>/themes/powerlevel10k </code></pre></div> <p>Now, gotta set <code>ZSH_THEME="powerlevel10k/powerlevel10k"</code> in <code>~/.zshrc</code> by adding that manually in the&nbsp;file.</p> <h2 id="step-4-make-sure-the-prompt-looks-like-as-you-want">Step-4: Make sure the prompt looks like as you want<a class="headerlink" href="#step-4-make-sure-the-prompt-looks-like-as-you-want" title="Permanent link">&para;</a></h2> <p>In this step, I&rsquo;m gonna bring in my already open-sourced Zsh config file aka <code>.zshrc</code>. </p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp"># </span>deleting the current one <span class="p">&amp;</span> get my personal one from GitHub <span class="linenos" data-linenos="2 "></span><span class="gp">$ </span>rm .zshrc <span class="linenos" data-linenos="3 "></span><span class="gp">$</span> <span class="linenos" data-linenos="4 "></span><span class="gp">$ </span>wget https://raw.githubusercontent.com/kmonsoor/dot-files/master/.zshrc </code></pre></div> <p>I kept the powerlevel10k configs as comments so that Zsh doesn&rsquo;t complain if I use the config file early. Have to set <code>ZSH_THEME="powerlevel10k/powerlevel10k"</code> in the <code>~/.zshrc</code> as&nbsp;well.</p> <p>Otherwise, once the <code>powerlevel10k</code> theme will run for the first time by Zsh, a very friendly step-by-step prompt will run you through towards a desirable prompt for you. Also, whenever you want, you can invoke the config-wizard by executing <code>p10k configure</code> on the&nbsp;shell.</p> <p>Now is the time to enable the changes by restarting Zsh and enjoy the new config and the powerful&nbsp;prompt.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span><span class="nb">exec</span> zsh </code></pre></div> <h2 id="optional">Optional<a class="headerlink" href="#optional" title="Permanent link">&para;</a></h2> <p>Also, I usually install this very useful, but external plugin <code>zsh-syntax-highlighting</code> for&nbsp;oh-my-zsh.</p> <p><div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>git clone https://github.com/zsh-users/zsh-syntax-highlighting.git <span class="si">${</span><span class="nv">ZSH_CUSTOM</span><span class="k">:-</span><span class="p">~/.oh-my-zsh/custom</span><span class="si">}</span>/plugins/zsh-syntax-highlighting </code></pre></div> Don&rsquo;t forget to activate the plugin by including it in ~/.zshrc. For that, add <code>zsh-syntax-highlighting</code> inside the list of other&nbsp;plugins.</p> <p>plugins=( plugin_a plugin_b&nbsp;zsh-syntax-highlighting)</p>Ubuntu - Update APT-GET Server to Use Fastest Mirror2016-10-10T00:00:00+06:002016-10-10T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2016-10-10:/ubuntu-update-apt-get-server-to-use-fastest-mirror/<p>Updating Ubuntu from it&rsquo;s default server takes too damn long. Give it a 10x&nbsp;boost.</p><h2 id="prelude">Prelude<a class="headerlink" href="#prelude" title="Permanent link">&para;</a></h2> <p>By default, Ubuntu sets the update server pointing to its own (<a href="http://archive.ubuntu.com">http://archive.ubuntu.com</a>). It is the safest bet for Ubuntu. But, that&rsquo;s not the case for users, especially who are outside <span class="caps">USA</span>. To make it smoother as well as distribute the load, Ubuntu also provides a list of mirror sites. You can find the official mirror list <a href="https://launchpad.net/ubuntu/+archivemirrors">here</a>. </p> <p>However, it needs some&nbsp;configuration.</p> <h2 id="on-gui">On <span class="caps">GUI</span><a class="headerlink" href="#on-gui" title="Permanent link">&para;</a></h2> <p>Yes, you can do the selection on Ubuntu using its <span class="caps">GUI</span> tool. But, the problem is it don&rsquo;t always work as you&nbsp;want.</p> <blockquote> <p>It works on geolocation, giving me the local server, which is waaaayy slower where I am. The network temporal distance is the important factor here, not spatial distance (<a href="http://askubuntu.com/a/9035/113604">http://askubuntu.com/a/9035/113604</a>)</p> </blockquote> <p><img alt="Ubuntu-select-update-server-GUI" src="http://i.imgur.com/sCWr0zrl.png"></p> <h2 id="so-what-else-do-we-have">so, what else do we have ?<a class="headerlink" href="#so-what-else-do-we-have" title="Permanent link">&para;</a></h2> <p>I use a handy tool for this purpose to point me to the fastest server <span class="caps">FOR</span> <span class="caps">ME</span>. It&rsquo;s <a href="https://github.com/jblakeman/apt-select">apt-select</a>.</p> <p>To install it, i found this method most hassle-free. You may also try <code>pip install</code> method described on the repo&rsquo;s <span class="caps">README</span>&nbsp;file.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>git clone https://github.com/jblakeman/apt-select.git </code></pre></div> <p>That&rsquo;s it. Now to execute it, just run the &ldquo;main&rdquo; Python&nbsp;file.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span><span class="nb">cd</span> apt-select <span class="hll"><span class="linenos" data-linenos="2 "></span><span class="gp">$ </span>./apt-select.py -c -t <span class="m">3</span> -m one-week-behind </span></code></pre></div> <p>We are choosing here the best 3 mirrors(due to <code>-t 3</code>) which are at most <code>one week behind</code> from the main Ubuntu server. For general purposes, that&rsquo;s good&nbsp;enough.</p> <p>It will choose one using the latency <span class="amp">&amp;</span> ping time, and also show servers&rsquo; bandwidth. Then the tool asks you to select new mirror from the <code>3</code> options came up. Usually, stick to the top option, hence <code>1</code>. For example in my case, it&nbsp;shows:</p> <div class="highlight"><pre><span></span><code><span class="hll"><span class="linenos" data-linenos=" 1 "></span><span class="gp">[khaled:~] $ </span>apt-select -c -t <span class="m">3</span> -m one-week-behind </span><span class="linenos" data-linenos=" 2 "></span><span class="go">Getting list of mirrors...done.</span> <span class="linenos" data-linenos=" 3 "></span><span class="go">Testing latency to mirror(s)</span> <span class="linenos" data-linenos=" 4 "></span><span class="go">[3/3] 100%</span> <span class="linenos" data-linenos=" 5 "></span><span class="go">Getting list of launchpad URLs...done.</span> <span class="linenos" data-linenos=" 6 "></span><span class="go">Looking up 3 status(es)</span> <span class="linenos" data-linenos=" 7 "></span><span class="go">[3/3] 100%</span> <span class="linenos" data-linenos=" 8 "></span><span class="go">1. mirror.dhakacom.com (current)</span> <span class="linenos" data-linenos=" 9 "></span><span class="go"> Latency: 1.89 ms</span> <span class="linenos" data-linenos="10 "></span><span class="go"> Org: dhakaCom Limited</span> <span class="linenos" data-linenos="11 "></span><span class="go"> Status: Up to date</span> <span class="linenos" data-linenos="12 "></span><span class="go"> Speed: 1 Gbps</span> <span class="linenos" data-linenos="13 "></span><span class="go">2. mirror.dhakacom.com</span> <span class="linenos" data-linenos="14 "></span><span class="go"> Latency: 1.96 ms</span> <span class="linenos" data-linenos="15 "></span><span class="go"> Org: dhakaCom Limited</span> <span class="linenos" data-linenos="16 "></span><span class="go"> Status: Up to date</span> <span class="linenos" data-linenos="17 "></span><span class="go"> Speed: 1 Gbps</span> <span class="linenos" data-linenos="18 "></span><span class="go">3. archive.ubuntu.com</span> <span class="linenos" data-linenos="19 "></span><span class="go"> Latency: 205.23 ms</span> <span class="linenos" data-linenos="20 "></span><span class="go"> Org: Canonical Ltd.</span> <span class="linenos" data-linenos="21 "></span><span class="go"> Status: Up to date</span> <span class="linenos" data-linenos="22 "></span><span class="go"> Speed: 100 Mbps</span> <span class="linenos" data-linenos="23 "></span><span class="go">Choose a mirror (1 - 3)</span> <span class="linenos" data-linenos="24 "></span><span class="go">&#39;q&#39; to quit 1</span> <span class="linenos" data-linenos="25 "></span><span class="go">New config file saved to /home/khaled/sources.list</span> </code></pre></div> <p>Then, the tool prepares a new <code>sources.list</code> file to replace the system&rsquo;s one&nbsp;with.</p> <p>Now, replace the file with the new one which will be now used by the <code>apt-get *</code> commands. As it overwrites a system config file, you need to do with <code>sudo</code>.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup <span class="o">&amp;&amp;</span> sudo mv sources.list /etc/apt/ </code></pre></div> <p>That&rsquo;s it. Now, all you update/upgrade will be fetched from the newly selected&nbsp;mirror.</p> <p>However, I highly recommend to run <code>update</code> once right&nbsp;away.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo apt-get update </code></pre></div> <p>Then, only if you want, run <code>upgrade</code>:</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo apt-get upgrade </code></pre></div> <hr> <h2 id="you-may-also-like">You may also like<a class="headerlink" href="#you-may-also-like" title="Permanent link">&para;</a></h2> <ul> <li><a href="https://blog.kmonsoor.com/open-source-as-if-you-gonna-die-tonight/?utm_source=related_footer&amp;utm_keyword=coding">Open Source as-if You Gonna Die&nbsp;Tonight</a></li> <li><a href="https://blog.kmonsoor.com/pelican-how-to-make-seo-friendly/?utm_source=related_footer&amp;utm_keyword=python">Pelican Static sites - <span class="caps">SEO</span>&nbsp;Optimization</a></li> <li><a href="https://blog.kmonsoor.com/generate-er-diagram-from-sql-database/?utm_source=related_footer&amp;utm_keyword=coding">Generate <span class="caps">ER</span> diagram from a <span class="caps">SQL</span>-based&nbsp;database</a></li> </ul>Increase virtual-disk size in VirtualBox on Windows 72012-05-26T08:02:00+06:002012-05-26T08:02:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2012-05-26:/increase-virtual-disk-size-in-virtualbox-windows/<p>Stuck with your small virtual disk partition for VirtualBox? I also stuck with same problem; researched many forums, and here is the gist. Find out&nbsp;how.</p><p>Are you stuck with your small virtual disk partition for VirtualBox? You created the partition for some testing <span class="amp">&amp;</span> practicing, now it needs more space. I was also stuck with the same problem; so I researched many forums, and here is the&nbsp;gist.</p> <p>[Note: This procedure won&rsquo;t work for <span class="caps">VM</span> with snapshots. So, please take note the fact about your system&nbsp;beforehand.]</p> <ul> <li>Download <a href="http://gparted.org/download.php">Gparted</a>, disk manager for Linux. It&rsquo;ll come as an <span class="caps">ISO</span>&nbsp;file.</li> <li>Boot into your guest <span class="caps">OS</span>, check, with df command, which partition you need to grow. Take note of that specific mounted <span class="caps">HD</span>, such as&nbsp;/dev/hdb/sda3</li> <li>Take backup of your existing data, as I <span class="caps">WILL</span> <span class="caps">NOT</span> <span class="caps">TAKE</span> <span class="caps">ANY</span> <span class="caps">RESPONSIBILITY</span> <span class="caps">IF</span> <span class="caps">YOU</span> <span class="caps">DAMAGE</span> <span class="caps">YOUR</span> <span class="caps">DATA</span>.</li> <li>In host <span class="caps">OS</span>, Goto the command prompt by running,&nbsp;cmd.exe</li> <li>Navigate to the Virtualbox installation&nbsp;folder</li> <li>Execute the&nbsp;command:</li> </ul> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="go">C:\ VBoxManage modifyhd X:\yourVM_DiskPath_InHost\yourVM_Disk.vdi --resize 40960</span> </code></pre></div> <p>you will see progress as&nbsp;below:</p> <p><img alt="10% ... 20% .. .. 100%" src="http://i.imgur.com/iYORelg.png"></p> <p>If you fail with a message like&nbsp;thid</p> <blockquote> <p><span class="dquo">&ldquo;</span>VBoxManage.exe: error: Resize hard disk operation for this format is not implemented&nbsp;yet!&rdquo;</p> </blockquote> <p>Now, you need this tool <a href="https://forums.virtualbox.org/download/file.php?id=7579">CloneVDI.exe</a> from this VirtualBox forum-post. If you&rsquo;re using this tool, remember to check &ldquo;Increase virtual drive size to &rdquo; with your desired&nbsp;size.</p> <p><img alt="VDI_tool" src="http://i.imgur.com/YB49ZVk.png"></p> <ul> <li>Now, Load the <span class="caps">ISO</span> file to the <span class="caps">CD</span>/<span class="caps">DVD</span> drive of your virtual&nbsp;Linux.</li> </ul> <p><img alt="GParted.iso loaded on IDE Primary Master" src="http://i.imgur.com/UKyPkl8.png"></p> <ul> <li>Boot the Guest <span class="caps">OS</span>; from the boot menu, select <span class="caps">CD</span>/<span class="caps">DVD</span> drive, then it will boot in GParted tiny <span class="caps">OS</span>. Now the PartitionManager tool will come up automatically, like&nbsp;below:</li> </ul> <p><img alt="Gparted partition-manager" src="http://i.imgur.com/aK9kAtK.jpg"></p> <ul> <li>Now &ldquo;shrink/Grow&rdquo; or &ldquo;Move&rdquo; your desired partition, but be careful. Don&rsquo;t rename any of them. Be careful about your&nbsp;data.</li> <li>Don&rsquo;t worry, unless you clicked Apply, nothing has actually took place. When you are done with moving and resizing, you have to click <strong><code>Apply</code></strong> to commit the&nbsp;change</li> </ul> <p><img alt="just before applying" src="http://i.imgur.com/wUMCHVQ.jpg"></p> <ul> <li>Once completed, close Gparted, and then shutdown the <span class="caps">OS</span></li> <li>Unload the <span class="caps">ISO</span> aka virtual <span class="caps">CD</span> from virtual <span class="caps">OS</span></li> <li>Boot into the virtual <span class="caps">OS</span>&nbsp;again</li> <li>Now, check that if the desired partition grew or not by using the <code>df</code> command</li> </ul> <p>Thanks for visiting my blog. If it just helped you, please feel free to &ldquo;Like&rdquo; or &ldquo;share&rdquo;. Also, your suggestion or comment would be great as&nbsp;well.</p> <hr> <p>If you find this post helpful, you can show your support <a href="https://www.patreon.com/kmonsoor">through Patreon</a> or <a href="https://paypal.me/KhaledMonsoor/">Paypal</a> or by <a href="https://ko-fi.com/kmonsoor">buying me a coffee</a>. <em>Thanks!</em></p>How to install and use `UNAFold` / `mfold` RPM package on Ubuntu2011-02-17T00:00:00+06:002011-02-17T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2011-02-17:/install-and-use-unafold-mfold-rpm-package-in-ubuntu/<p>I failed to install UNAFold/mfold in Ubuntu 10.10 as the supplied binary package was in rpm (RedHat) format. How to solve&nbsp;it?</p><p>[Please note that this post has been written quite a while ago. After that, it hasn&rsquo;t been updated&nbsp;much.]</p> <p>I failed to install UNAFold/mfold in Ubuntu 10.10 as the supplied binary package was in rpm (RedHat)&nbsp;format.</p> <p><code>Ubuntu 10.10</code> can&rsquo;t use rpm files to install software&nbsp;directly.</p> <p>After doing some digging, I found that it is possible to convert rpm files to deb(Debian) format by using another app, named <code>alien</code>.</p> <p>But <code>alien</code> isn&rsquo;t installed on Ubuntu by default. So I used the&nbsp;command,</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo apt-get install alien </code></pre></div> <p>then check the&nbsp;installation:</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>alien </code></pre></div> <p>if it goes okay, now to simply convert the UNAFold&nbsp;package:</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$</span>sudo alien ~/Downloads/unafold-3.8-1.i386.rpm </code></pre></div> <p>the converted one is named like <code>unafold_3.8-2_i386.deb</code></p> <p>Now use this new package for&nbsp;installation</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo dpkg -i unafold_3.8-2_i386.deb </code></pre></div> <p>after installation, you should be able to run the *.pl scripts with appropriate input,&nbsp;like:</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>perl /usr/bin/UNAFold.pl ~/s1.seq </code></pre></div>