<?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: chinmay chhajed</title>
    <description>The latest articles on DEV Community by chinmay chhajed (@chhajedji).</description>
    <link>https://dev.to/chhajedji</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%2F396455%2Fb0910f61-8aa4-41cd-b741-ee8e45ce20d4.jpg</url>
      <title>DEV Community: chinmay chhajed</title>
      <link>https://dev.to/chhajedji</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chhajedji"/>
    <language>en</language>
    <item>
      <title>Android vs iOS</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Fri, 30 Aug 2024 19:30:16 +0000</pubDate>
      <link>https://dev.to/chhajedji/android-vs-ios-1a4i</link>
      <guid>https://dev.to/chhajedji/android-vs-ios-1a4i</guid>
      <description>&lt;p&gt;After using Android phones for almost all the years and iPhone for about 3 months, here is an analysis comparing the features of both. I have used stock Android on Pixel and iOS on iPhone 15 Pro, so best of both worlds. &lt;/p&gt;

&lt;p&gt;A big factor in this comparison is that it just discusses the features of Android and iOS, not the complete infrastructure. I am pretty sure that if you add a Macbook, Airpods, and an iPad, the table might look way different.&lt;/p&gt;

&lt;p&gt;The following comparison lists Android 14 vs iOS 17.6 (just a few days before the release of iOS 18).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Android&lt;/th&gt;
&lt;th&gt;iOS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Notifications&lt;/td&gt;
&lt;td&gt;1 (+)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Widgets&lt;/td&gt;
&lt;td&gt;2 (+)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shortcuts/Automation  2 (N/A)&lt;/td&gt;
&lt;td&gt;1(+)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auto-complete&lt;/td&gt;
&lt;td&gt;3 (+)&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Keyboard navigation&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2 (+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Volume Control&lt;/td&gt;
&lt;td&gt;4 (+)&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Finger print/Face ID&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;3 (+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shazam/Music Recognition&lt;/td&gt;
&lt;td&gt;5 (+)&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Google Photos*&lt;/td&gt;
&lt;td&gt;6 (+)&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CarPlay/Android Auto*&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;4 (+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Display&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;5 (+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Action button&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;6 (+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Navigation (Home, back, clear all)&lt;/td&gt;
&lt;td&gt;7 (+)&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;App Management (Force Quit, Disable,clear memory, etc.)&lt;/td&gt;
&lt;td&gt;8 (+)&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Air Drop/Quick Share&lt;/td&gt;
&lt;td&gt;9 (+)&lt;/td&gt;
&lt;td&gt;7 (+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Messaging/Web support*&lt;/td&gt;
&lt;td&gt;10 (+)&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Launcher/Home screen customization flexibility&lt;/td&gt;
&lt;td&gt;11 (+)&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browser Support*&lt;/td&gt;
&lt;td&gt;12 (+)&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bluetooth Audio*&lt;/td&gt;
&lt;td&gt;13 (+)&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;*Google Photos&lt;/strong&gt;: Cannot select which albums to back up on iOS. iPhone backs up just everything.&lt;br&gt;
&lt;strong&gt;*CarPlay&lt;/strong&gt;: Personal preference. Just has better connectivity and UI.&lt;br&gt;
&lt;strong&gt;*Messaging&lt;/strong&gt;: RCS Messaging can be opened on any browser, and any machine, however, iMessage can only be opened on Macbooks.&lt;br&gt;
&lt;strong&gt;*Browser Support&lt;/strong&gt;: Everything on iOS runs the Safari engine in the back, so, browser cannot add its own new features.&lt;br&gt;
&lt;strong&gt;*Bluetooth Audio&lt;/strong&gt;: Same Bluetooth piece, same streaming app, but still those beats were more vibrant in Android.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>android</category>
      <category>ios</category>
      <category>mobile</category>
      <category>iphone</category>
    </item>
    <item>
      <title>Simple ransomware in Python</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Tue, 14 Jun 2022 03:31:02 +0000</pubDate>
      <link>https://dev.to/chhajedji/simple-ransomware-in-python-158b</link>
      <guid>https://dev.to/chhajedji/simple-ransomware-in-python-158b</guid>
      <description>&lt;p&gt;A ransomware is a piece of code that encrypts files and denies user access. The files can only be decrypted with the key used while encryption.&lt;/p&gt;

&lt;p&gt;In this project, Python's &lt;code&gt;Fernet&lt;/code&gt; module is used to generate keys, encrypt, and decrypt files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/chhajedji/ransomware/blob/master/encrypt.py"&gt;encrypt.py&lt;/a&gt; first generates a &lt;em&gt;key&lt;/em&gt; (key.key file).  This is being done by &lt;code&gt;Fernet.generate_key()&lt;/code&gt;. The key.key file stores the key which will be used to encrypt and further decrypt files. &lt;code&gt;encrypt.py&lt;/code&gt; recursively iterates and encrypts all the files present in the &lt;code&gt;root_dir&lt;/code&gt;. During encryption, we need to make sure that we are not encrypting the keys or the script used for encryption, or else that might have not end up well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/chhajedji/ransomware/blob/master/decrypt.py"&gt;decrypt.py&lt;/a&gt; iterates through files similar to encrypt.py. Just the difference is that instead of encrypting, it decrypts all the files using same key which was generated during encryption. Without that key, decryption wouldn't work.&lt;/p&gt;

&lt;p&gt;For recursively iterating files during encryption and decryption, &lt;a href="https://github.com/chhajedji/simple-snippets/tree/master/Python/filelister"&gt;FileLister&lt;/a&gt; is being used, which is just simple recursive way of listing all the files in a given directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;For encryption, either give no arguments to run throughout  &lt;code&gt;test_dir&lt;/code&gt; or give specific path:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a3F4tCri--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwn6xmbvpc7km1lrayvj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a3F4tCri--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwn6xmbvpc7km1lrayvj.png" alt="Image description" width="753" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For specific set of files:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3n4a_h7X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iompyz6cmmuidq68ppw1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3n4a_h7X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iompyz6cmmuidq68ppw1.png" alt="Image description" width="548" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Decryption:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wVYmVzr0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yu5kdgkt4fq7sfn78omw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wVYmVzr0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yu5kdgkt4fq7sfn78omw.png" alt="Image description" width="565" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For specific set of files:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vNrCFCR3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwsh9zdy0hb1s36bu0av.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vNrCFCR3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwsh9zdy0hb1s36bu0av.png" alt="Image description" width="734" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Project link: &lt;a href="https://github.com/chhajedji/ransomware"&gt;https://github.com/chhajedji/ransomware&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ransomware</category>
      <category>python</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Example showing usage of LD_PRELOAD environment variable in UNIX</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Fri, 29 Apr 2022 15:16:00 +0000</pubDate>
      <link>https://dev.to/chhajedji/example-showing-usage-of-ldpreload-environment-variable-in-unix-4pl1</link>
      <guid>https://dev.to/chhajedji/example-showing-usage-of-ldpreload-environment-variable-in-unix-4pl1</guid>
      <description>&lt;h1&gt;
  
  
  LD_PRELOAD
&lt;/h1&gt;

&lt;p&gt;We can use &lt;code&gt;LD_PRELOAD&lt;/code&gt; environment variable to set a location to fetch shared libraries. By setting this variable, we can overwrite the existing functions and make the standard command work differently, the way we want it to.&lt;/p&gt;

&lt;p&gt;The linker links the libraries in the path provided by &lt;code&gt;LD_PRELOAD&lt;/code&gt; for compiling the main file. Once a function is linked, when other instance of same function shows up, older location is ignored and the newer location is used.&lt;/p&gt;

&lt;p&gt;For example, let us try to overwrite the &lt;code&gt;puts&lt;/code&gt; function present in &lt;code&gt;stdio.h&lt;/code&gt; file.&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%2Fiw5zfp53dlycod8xfxvl.png" 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%2Fiw5zfp53dlycod8xfxvl.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider a file &lt;code&gt;main.c&lt;/code&gt;, with following content:&lt;/p&gt;

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

  &lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;theFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;puts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;argc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;theFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, this is traditional work flow."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%s: puts location: %p&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;puts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Compiling and running the &lt;code&gt;main.c&lt;/code&gt; file gives following output with location of &lt;code&gt;puts&lt;/code&gt; as &lt;code&gt;0x7f877af52ef0&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%2Fhair6f3orm93iar6cmu3.png" 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%2Fhair6f3orm93iar6cmu3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create another file, &lt;code&gt;unmain.c&lt;/code&gt; as follows:&lt;/p&gt;

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

  &lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;puts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;__s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"New puts, hackerman alert!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now, create a shared library of this &lt;code&gt;unmain.c&lt;/code&gt; file with command:&lt;/p&gt;

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

  gcc &lt;span class="nt"&gt;-fPIC&lt;/span&gt; unmain.c &lt;span class="nt"&gt;-shared&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; unmain.so


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

&lt;/div&gt;

&lt;p&gt;Update the &lt;code&gt;LD_PRELOAD&lt;/code&gt; with the location of the shared library, &lt;code&gt;unmain.so&lt;/code&gt;:&lt;/p&gt;

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

  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;LD_PRELOAD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;/unmain.so"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;And then again run the first compiled &lt;code&gt;main.c&lt;/code&gt; file's executable &lt;code&gt;main.o&lt;/code&gt; to see that the location of the &lt;code&gt;puts&lt;/code&gt; has been updated. For my case, new location has been set to &lt;code&gt;0x7f6003f5d119&lt;/code&gt;.&lt;/p&gt;

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

  ./main.o


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

&lt;/div&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%2Fuesy6k6uuvya8361mdb1.png" 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%2Fuesy6k6uuvya8361mdb1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To remove the shared library, use &lt;code&gt;unset&lt;/code&gt; to unset value of&lt;br&gt;
&lt;code&gt;LD_PRELOAD&lt;/code&gt;.&lt;/p&gt;

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

  &lt;span class="nb"&gt;unset &lt;/span&gt;LD_PRELOAD


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

&lt;/div&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%2F8qw6a6e9hisi5gu3xhq2.png" 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%2F8qw6a6e9hisi5gu3xhq2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Same example to contribute on Github: &lt;a href="https://github.com/chhajedji/ld-preload" rel="noopener noreferrer"&gt;https://github.com/chhajedji/ld-preload&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bash</category>
      <category>c</category>
      <category>linux</category>
      <category>shell</category>
    </item>
    <item>
      <title>Make fzf your best friend inside terminal</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Sat, 05 Jun 2021 11:56:28 +0000</pubDate>
      <link>https://dev.to/chhajedji/make-fzf-your-best-friend-inside-terminal-iod</link>
      <guid>https://dev.to/chhajedji/make-fzf-your-best-friend-inside-terminal-iod</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/junegunn/fzf"&gt;Fuzzy finder&lt;/a&gt; is one of the best tool which you can use for speeding up your daily terminal work flow. In my daily workflow, I have integrated &lt;code&gt;fzf&lt;/code&gt; in most of the tasks where I have many choices and have to choose one among them, whether be it changing a git branch, searching and opening a file, changing directory or changing a project.&lt;/p&gt;

&lt;p&gt;Let's get started to exploit some features of &lt;code&gt;fzf&lt;/code&gt; 😈&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;

&lt;p&gt;Probably your &lt;a href="https://github.com/junegunn/fzf#using-linux-package-managers"&gt;package manager already has it&lt;/a&gt;. If it doesn't, don't worry, just clone the git repo and run the &lt;code&gt;install&lt;/code&gt; script as directed &lt;a href="https://github.com/junegunn/fzf#using-git"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can check if the installation has been successful by running the command &lt;code&gt;whereis fzf&lt;/code&gt;. You should see the location of binary.&lt;/p&gt;

&lt;p&gt;Make sure to read the &lt;code&gt;README.md&lt;/code&gt; from the project's Github. It explains &lt;code&gt;fzf&lt;/code&gt; and some of it's usage quite well. Specially the &lt;a href="https://github.com/junegunn/fzf#key-bindings-for-command-line"&gt;key-binding&lt;/a&gt; part, where you can map &lt;code&gt;Ctrl-t&lt;/code&gt; to paste the selected files and directories onto the command-line, &lt;code&gt;Alt-c&lt;/code&gt; for changing directories and &lt;code&gt;Ctrl-r&lt;/code&gt; for fuzzy reverse searching. Also if you happen to use &lt;code&gt;vim&lt;/code&gt;, you may check the &lt;a href="https://github.com/junegunn/fzf#vim-plugin"&gt;vim extension&lt;/a&gt; for same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some other usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Changing git projects
&lt;/h3&gt;

&lt;p&gt;Add the following alias in your bashrc:&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;# Find and save location of all git repositories present in $HOME.&lt;/span&gt;
&lt;span class="c"&gt;# Try using `fd', if not installed then use default `find'.&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;repoup&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"fd -HI ^&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;git&lt;/span&gt;&lt;span class="nv"&gt;$ $HOME&lt;/span&gt;&lt;span class="s2"&gt; 2&amp;gt;/dev/null &amp;gt; &lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.tmp/gitfiles || find &lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/ -regex .*/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;git&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;2&amp;gt;/dev/null &amp;gt; &lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.tmp/gitfiles"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If you happen to use &lt;code&gt;fd&lt;/code&gt; (&lt;a href="https://dev.to/chhajedji/why-to-find-files-when-you-can-fd-them-26ej"&gt;which definitely you should&lt;/a&gt;), this command will be completed in a wink.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Executing this alias will use search path of all git repositories stored inside &lt;code&gt;HOME&lt;/code&gt; and list them in file at &lt;code&gt;~/.tmp/gitfiles&lt;/code&gt;. This file will be further used with &lt;code&gt;fzf&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Make sure to execute this alias whenever you add a new git repository in your system. This will update the paths of all git repositories, specially the newly added one.&lt;/p&gt;

&lt;p&gt;Next, add this function in your bashrc file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gotoprj&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;REPOS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.tmp/gitfiles | xargs &lt;span class="nb"&gt;dirname&lt;/span&gt;  | &lt;span class="nb"&gt;sed &lt;/span&gt;s:/home/&lt;span class="nv"&gt;$USER&lt;/span&gt;:~: | fzf&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Cut the '~/' part from the `REPOS'.&lt;/span&gt;
        &lt;span class="nv"&gt;REPOS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$REPOS&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="nt"&gt;-f2-&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# If user selected any repo then open `$TERMINAL' in that repo.&lt;/span&gt;
        &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$REPOS&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/&lt;span class="nv"&gt;$REPOS&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will list all the git repositories present in our database created in last step (&lt;code&gt;~/.tmp/gitfiles&lt;/code&gt;) , and change current directory to that repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Switch to any directory
&lt;/h3&gt;

&lt;p&gt;As simple as said in title, from any current directory, switch to any directory in you system by just typing the keywords you remember specific to target directory. Have this function in your bashrc:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sd&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt; fd &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt; &lt;span class="nt"&gt;--type&lt;/span&gt; directory &lt;span class="nt"&gt;-HI&lt;/span&gt; 2&amp;gt;/dev/null &lt;span class="o"&gt;||&lt;/span&gt; find &lt;span class="nv"&gt;$HOME&lt;/span&gt; &lt;span class="nt"&gt;-type&lt;/span&gt; d 2&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt; | fzf&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TARGET&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TARGET&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now whenever you want to go to any directory, instead of giving it's full path, just hit &lt;code&gt;sd&lt;/code&gt; and give the directory name and few unique words in it's path, and Tada 🎉! No need to enter that ugly full path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Change git branch
&lt;/h3&gt;

&lt;p&gt;Many times it happens that I forget the branch name I want to switch to. Again, doing it with &lt;code&gt;fzf&lt;/code&gt; saves the pain for searching the branch name. What can be done is add following section in your gitconfig file which should be present at &lt;code&gt;$HOME/.gitconfig&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;[&lt;span class="n"&gt;alias&lt;/span&gt;]
    ; &lt;span class="n"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt; &lt;span class="n"&gt;branches&lt;/span&gt; &lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;fzf&lt;/span&gt;
    &lt;span class="n"&gt;sb&lt;/span&gt;=&lt;span class="s2"&gt;"!switch_branch_fzf() { git branch | fzf | xargs git checkout; }; switch_branch_fzf"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note that since we are using &lt;code&gt;git branch&lt;/code&gt;, it will only list the branches you have previously checked out. New branches will not appear in the finder.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Usage
&lt;/h4&gt;



&lt;p&gt;&lt;code&gt;git sb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This will list all the git branches in &lt;code&gt;fzf&lt;/code&gt; and now we can search for the target branch with ease.&lt;/p&gt;

&lt;p&gt;Once you get the idea of using the fuzzy finder, you can modify it to find anything which you need to search on regular basis. For example, if you have a location where you store all the scripts which you edit frequently, you can have a function to list all of them into &lt;code&gt;fzf&lt;/code&gt; and then open the selected one in your editor. These were just some of the exploits I use. If you have anything more to suggest, add it in the comments.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>terminal</category>
      <category>shell</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Why to `find` files when you can `fd` them ;)</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Thu, 11 Mar 2021 09:35:44 +0000</pubDate>
      <link>https://dev.to/chhajedji/why-to-find-files-when-you-can-fd-them-26ej</link>
      <guid>https://dev.to/chhajedji/why-to-find-files-when-you-can-fd-them-26ej</guid>
      <description>&lt;p&gt;If you happen to be a frequent terminal user, you must be using the GNU &lt;code&gt;find&lt;/code&gt; command to know the location of files. But as the number of files increase, you can see a significant increase in runtime of &lt;code&gt;find&lt;/code&gt;. This is where the younger sibling &lt;a href="https://github.com/sharkdp/fd" rel="noopener noreferrer"&gt;&lt;code&gt;fd&lt;/code&gt;&lt;/a&gt; comes in picture ;)&lt;/p&gt;

&lt;p&gt;According to the &lt;a href="https://github.com/sharkdp/fd" rel="noopener noreferrer"&gt;README of the project&lt;/a&gt;, some highlights of &lt;code&gt;fd&lt;/code&gt; are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Very fast due to parallelized directory traversal.&lt;/li&gt;
&lt;li&gt;Uses colors to highlight different file types (same as ls).&lt;/li&gt;
&lt;li&gt;The command name is 50% shorter than find :-)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For installation, most package managers like &lt;code&gt;brew&lt;/code&gt;, &lt;code&gt;apt&lt;/code&gt;, &lt;code&gt;dnf&lt;/code&gt;, &lt;code&gt;pacman&lt;/code&gt;, &lt;code&gt;emerge&lt;/code&gt;, &lt;code&gt;zypper&lt;/code&gt; and others have &lt;code&gt;fd&lt;/code&gt;  package so you can just run the standard installation command. For more details, see the &lt;a href="https://github.com/sharkdp/fd#installation" rel="noopener noreferrer"&gt;installation guide&lt;/a&gt; for your system.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that for Debian based distros like Ubuntu and others, you will have to install &lt;code&gt;fdfind&lt;/code&gt; because &lt;code&gt;fd&lt;/code&gt; is already used by a different package. You can see &lt;a href="https://github.com/sharkdp/fd#on-ubuntu" rel="noopener noreferrer"&gt;the guide&lt;/a&gt; how to use &lt;code&gt;fd&lt;/code&gt; on Ubuntu instead of &lt;code&gt;fdfind&lt;/code&gt;. Spoiler alert: It's not about creating alias. xD&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Personally, I am very impressed with the speed of &lt;code&gt;fd&lt;/code&gt;. When I had to wait for few seconds for &lt;code&gt;find&lt;/code&gt; to finish, &lt;code&gt;fd&lt;/code&gt; does the work within a second. Also, if you know regex , &lt;code&gt;fd&lt;/code&gt; is a big blessing as it uses regex for searching.&lt;/p&gt;

&lt;p&gt;Coming to some numbers from comparison:&lt;/p&gt;

&lt;p&gt;Number of all &lt;code&gt;.png&lt;/code&gt; files in my home directory searched with &lt;code&gt;find&lt;/code&gt;:&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;# Do a regex search with `find` with ignoring case&lt;/span&gt;
&lt;span class="c"&gt;# and piping output to `wc -l` which will count number&lt;/span&gt;
&lt;span class="c"&gt;# of lines in result &lt;/span&gt;
find ~/ &lt;span class="nt"&gt;-iregex&lt;/span&gt; &lt;span class="s1"&gt;'.*\.png$'&lt;/span&gt; 2&amp;gt;/dev/null | &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;span class="c"&gt;# 13530 results found&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Number of all &lt;code&gt;.png&lt;/code&gt; files in my home directory searched with &lt;code&gt;fd&lt;/code&gt;:&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;# Same regex, but now with `fd`&lt;/span&gt;
&lt;span class="c"&gt;# -H flag to search in hidden directories&lt;/span&gt;
&lt;span class="c"&gt;# -I to not ignore any files. `fd` ignores files like&lt;/span&gt;
&lt;span class="c"&gt;# .gitignore, .ignore, .fdignore&lt;/span&gt;

fd &lt;span class="nt"&gt;-HI&lt;/span&gt; &lt;span class="s1"&gt;'.*\.png$'&lt;/span&gt; ~/ 2&amp;gt;/dev/null | &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;span class="c"&gt;# 13530 results found&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the number of results are same in both cases.&lt;/p&gt;

&lt;p&gt;Now let's see the time taken for each command.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;find&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;time&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;find ~/ &lt;span class="nt"&gt;-iregex&lt;/span&gt; &lt;span class="s1"&gt;'.*\.png$'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# real    0m3.892s&lt;/span&gt;
&lt;span class="c"&gt;# user    0m2.944s&lt;/span&gt;
&lt;span class="c"&gt;# sys     0m0.937s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fd&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;time&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;fd &lt;span class="nt"&gt;-HI&lt;/span&gt; &lt;span class="s1"&gt;'.*\.png$'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# real    0m0.607s&lt;/span&gt;
&lt;span class="c"&gt;# user    0m2.110s&lt;/span&gt;
&lt;span class="c"&gt;# sys     0m1.779s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, &lt;code&gt;fd&lt;/code&gt; is more than 6 times faster than the GNU &lt;code&gt;find&lt;/code&gt;. When you find files frequently, the time saved is quite significant! Experiencing the power of  &lt;code&gt;fd&lt;/code&gt; can be easily done with other programs like &lt;code&gt;fzf&lt;/code&gt; and &lt;code&gt;dmenu&lt;/code&gt; which I'll keep for another post ;).&lt;/p&gt;

&lt;p&gt;Screenshots of above commands and their outputs for my system:&lt;br&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%2Fpu2paqgc579gt631yevd.png" 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%2Fpu2paqgc579gt631yevd.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>shell</category>
      <category>bash</category>
      <category>terminal</category>
    </item>
    <item>
      <title>Transfer files between your phone and computer without any cable and internet!</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Mon, 22 Feb 2021 08:53:35 +0000</pubDate>
      <link>https://dev.to/chhajedji/transfer-data-between-your-phone-and-computer-without-any-cable-28m5</link>
      <guid>https://dev.to/chhajedji/transfer-data-between-your-phone-and-computer-without-any-cable-28m5</guid>
      <description>&lt;p&gt;Isn't it tedious to always reach out for a USB cable and then connect phone with computer, wait while computer detects, then browse for files and then finally transfer! What a pain to do so many steps.&lt;/p&gt;

&lt;p&gt;Worry not, here is a &lt;em&gt;wireless&lt;/em&gt; solution to copy data from one device to other. All you need is Python and a supporting mobile app!&lt;/p&gt;

&lt;p&gt;To do this, we will be using a simple concept: HTTP Server and Client. A server will be source of files and a client will be the one copying files from server.&lt;/p&gt;

&lt;p&gt;Since we will be transferring files wireless, we need to connect mobile and computer to a common WiFi router. If you don't have a router, turn hotspot on from your mobile and connect your computer to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transfer files from computer to phone
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Make sure you have python installed. If not then first &lt;a href="https://www.python.org/downloads/" rel="noopener noreferrer"&gt;install python&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Next step is to check version of python. Open a terminal (or command prompt on Windows) and run &lt;code&gt;python --version&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you have a python version starting from &lt;code&gt;3.x&lt;/code&gt;, then run the command &lt;code&gt;python -m http.server&lt;/code&gt; in terminal.&lt;/li&gt;
&lt;li&gt;If your python version is &lt;code&gt;2.x&lt;/code&gt; then run &lt;code&gt;python -m SimpleHTTPServer&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Output should look something like this in both the cases:&lt;br&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%2Fc1uo9k3z22pgok5ghwip.png" 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%2Fc1uo9k3z22pgok5ghwip.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Next get the private IP address of your machine.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Windows, open command prompt and run &lt;code&gt;ipconfig&lt;/code&gt;. Your local IP address will be listed under ‘IPv4 Address’.&lt;/li&gt;
&lt;li&gt;For Linux and Mac, open terminal and run command &lt;code&gt;ifconfig&lt;/code&gt;. In the resulting information spewed out, we are looking for the section starting with &lt;code&gt;wl&lt;/code&gt;. It could be &lt;code&gt;wlp3s0&lt;/code&gt; or something else. Basically it denotes wireless lan. Under this section, we need address after &lt;code&gt;inet&lt;/code&gt;. In my case, it's &lt;code&gt;192.168.10.11&lt;/code&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%2F46kajsrj1f41kxobo12h.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Once we have the IP address, go to the browser in your phone and enter that address with a &lt;code&gt;:8000&lt;/code&gt; at the end in address bar. This &lt;code&gt;8000&lt;/code&gt; comes from the output of &lt;code&gt;python -m http.server&lt;/code&gt; command. As you can see in above image, default port is &lt;code&gt;8000&lt;/code&gt;. For my case, I would enter &lt;code&gt;192.168.10.11:8000&lt;/code&gt; in my mobile browser and go to the link. Once the page loads, congrats, you may navigate to the file and download it.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;If page doesn't load in mobile browser, make sure that you do not have a &lt;code&gt;https://&lt;/code&gt; at start of URL. If present then remove it.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Mobile browser for my case:&lt;br&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%2F03rqfk30jsn0k2nht76m.png" 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%2F03rqfk30jsn0k2nht76m.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Bonus: If you need a specific file, then in terminal navigate to the directory where file is present and run the python server command in that directory. Python server will start from which ever directory command is executed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Transfer files from phone to computer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For this you will need a mobile app to run HTTP Server like &lt;a href="https://play.google.com/store/apps/details?id=jp.ubi.common.http.server&amp;amp;hl=en&amp;amp;gl=US" rel="noopener noreferrer"&gt;this&lt;/a&gt; or any other app. Just open the app and run the server. For this app, click on "off" to turn the server on.
&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%2Fphe2sdnnbdosv06zxfur.png" alt="alt text"&gt;

&lt;ul&gt;
&lt;li&gt;Open the link given on computer browser. From above screenshot, &lt;code&gt;192.168.10.2:12345/&lt;/code&gt;. And done! Browser files present in your phone from your computer.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>productivity</category>
      <category>python</category>
      <category>lifehack</category>
      <category>wifi</category>
    </item>
    <item>
      <title>Bash: Edit command in your editor and execute directly</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Sat, 20 Feb 2021 14:04:11 +0000</pubDate>
      <link>https://dev.to/chhajedji/bash-edit-command-in-your-editor-and-execute-directly-30ef</link>
      <guid>https://dev.to/chhajedji/bash-edit-command-in-your-editor-and-execute-directly-30ef</guid>
      <description>&lt;p&gt;Sometimes we need to enter same command multiple times by changing 1 or 2 arguments. This is very tedious job to do. Update and execute command every single time!&lt;/p&gt;

&lt;p&gt;But worry not as what you are going to see in next few minutes will act as a big time savior in such cases.&lt;/p&gt;

&lt;p&gt;If you use shell in default mode (&lt;code&gt;emacs&lt;/code&gt; if you don't know :P), you can press &lt;code&gt;ctrl-x&lt;/code&gt; &lt;code&gt;ctrl-e&lt;/code&gt; and enter text editor to edit all the commands together by using features of your editor like copy, paste visually select etc. Save and exit editor to execute all the commands.&lt;/p&gt;

&lt;p&gt;If you are using &lt;code&gt;vi&lt;/code&gt; mode, you can move to normal mode by pressing &lt;code&gt;Esc&lt;/code&gt; and then pressing &lt;code&gt;v&lt;/code&gt; would achieve similar functionality.&lt;/p&gt;

&lt;p&gt;You can switch between &lt;code&gt;vi&lt;/code&gt; and &lt;code&gt;emacs&lt;/code&gt; mode by commands &lt;code&gt;set -o vi&lt;/code&gt; and &lt;code&gt;set -o emacs&lt;/code&gt; respectively. Your keybindings will work according to your mode.&lt;/p&gt;

&lt;p&gt;For my work, I use this script &lt;code&gt;poolfetch&lt;/code&gt; a lot with arguments varying only 1 or 2 characters. This functionality is very handy for me at such times.&lt;/p&gt;

&lt;p&gt;Here is a sample usage of this feature in &lt;code&gt;emacs&lt;/code&gt; mode:&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%2Fdfwr4d16bgkxaa2h426j.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%2Fdfwr4d16bgkxaa2h426j.gif" alt="change3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Edit:
&lt;/h4&gt;

&lt;p&gt;As suggested by  &lt;a href="https://dev.to/taikedz/comment/1bkb4"&gt;Tai Kedzierski here&lt;/a&gt;, you can choose the editor in which you want to edit commands by setting environment variable &lt;code&gt;EDITOR&lt;/code&gt; or &lt;code&gt;VISUAL&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;It's a good idea to set them in &lt;code&gt;$HOME/.bashrc&lt;/code&gt; or &lt;code&gt;$HOME/.profile&lt;/code&gt;. Former one will set it for every bash instance and latter one will set it globally which will be done at time of system startup. I prefer latter one.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>linux</category>
      <category>shell</category>
      <category>terminal</category>
    </item>
    <item>
      <title> Minimal and super useful shell prompt </title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Sat, 20 Feb 2021 11:54:48 +0000</pubDate>
      <link>https://dev.to/chhajedji/minimal-and-super-useful-shell-prompt-1g8l</link>
      <guid>https://dev.to/chhajedji/minimal-and-super-useful-shell-prompt-1g8l</guid>
      <description>&lt;p&gt;Primary shell prompt can be set by setting &lt;code&gt;PS1&lt;/code&gt; variable in shell's config file. Let's consider bash as our shell.&lt;/p&gt;

&lt;p&gt;Setting &lt;code&gt;PS1&lt;/code&gt; can be as simple as this&lt;/p&gt;

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

&lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"prompt $"&lt;/span&gt;
&lt;span class="c"&gt;# prompt $&lt;/span&gt;
&lt;span class="nb"&gt;echo &lt;/span&gt;value of PS1 is &lt;span class="nv"&gt;$PS1&lt;/span&gt;
&lt;span class="c"&gt;# value of PS1 is prompt $&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;To keep the changes permanent for our every terminal instant, add we will be updating our &lt;code&gt;.bashrc&lt;/code&gt; file located at &lt;code&gt;$HOME/.bashrc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Useful details in a shell prompt could be&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/chhajedji/add-current-working-directory-in-your-shell-prompt-5fca"&gt;Current directory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/chhajedji/add-time-stamp-in-your-shell-prompt-252c"&gt;Current time&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/chhajedji/background-jobs-add-to-your-shell-prompt-3eg2"&gt;Background jobs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/chhajedji/add-return-of-last-command-to-your-shell-prompt-58mh"&gt;Return status of previous command&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can go through above articles to add respective details in the prompt.&lt;/p&gt;

&lt;p&gt;If you are someone who likes colors more than text, we have a better option ;) We can differentiate the error and success of command by a different colors. When interested in error code, we can just print it with &lt;code&gt;echo $?&lt;/code&gt;. I will choose red color when previous command returned error and white when &lt;em&gt;all is well :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For our purpose, we will use 2 colors, bold red and bold white using &lt;code&gt;tput&lt;/code&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;# Red&lt;/span&gt;
&lt;span class="nv"&gt;bldred&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;tput setaf 1 2&amp;gt;/dev/null&lt;span class="si"&gt;)$(&lt;/span&gt;tput bold 2&amp;gt;/dev/null&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="c"&gt;# White&lt;/span&gt;
&lt;span class="nv"&gt;bldwht&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;tput setaf 7 2&amp;gt;/dev/null&lt;span class="si"&gt;)$(&lt;/span&gt;tput bold 2&amp;gt;/dev/null&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;And to reset colors to normal:&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;# Reset&lt;/span&gt;
&lt;span class="nv"&gt;txtrst&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;tput sgr 0 2&amp;gt;/dev/null&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://github.com/chhajedji/dot-files/blob/master/T480/.bash/colors.sh" rel="noopener noreferrer"&gt;Here&lt;/a&gt; are other variables for color codes set using &lt;code&gt;tput&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Our final function setting prompt would look something like this:&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;# Depth of `$PWD` is decided by this.&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PROMPT_DIRTRIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2

&lt;span class="c"&gt;# `exit_code' Should be first command in `PROMPT_COMMAND' to be&lt;/span&gt;
&lt;span class="c"&gt;# executed or else return status will always be 0/true (If functions in&lt;/span&gt;
&lt;span class="c"&gt;# `PROMPT_COMMAND' are written proper :)&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PROMPT_COMMAND&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;PROMPT_COMMAND&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"exit_code;&lt;/span&gt;&lt;span class="nv"&gt;$PROMPT_COMMAND&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nv"&gt;PROMPT_COMMAND&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"exit_code"&lt;/span&gt;

exit_code&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;EXIT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="c"&gt;# PS1 needs to be reset or else it will be appended every time to&lt;/span&gt;
    &lt;span class="c"&gt;# previous one.&lt;/span&gt;
    &lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;

    &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$EXIT&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"0"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;EXITCOL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$bldwht&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;EXITCOL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$bldred&lt;/span&gt;

    &lt;span class="c"&gt;# This will be final prompt, whatever set earlier will be&lt;/span&gt;
    &lt;span class="c"&gt;# overwritten by this.&lt;/span&gt;
    &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\[\$&lt;/span&gt;&lt;span class="s2"&gt;EXITCOL&lt;/span&gt;&lt;span class="se"&gt;\]\w\[\0&lt;/span&gt;&lt;span class="s2"&gt;33[01;38;5;208m&lt;/span&gt;&lt;span class="se"&gt;\]\$&lt;/span&gt;&lt;span class="s2"&gt;([ &lt;/span&gt;&lt;span class="se"&gt;\j&lt;/span&gt;&lt;span class="s2"&gt; -gt 0 ] &amp;amp;&amp;amp; echo [&lt;/span&gt;&lt;span class="se"&gt;\j&lt;/span&gt;&lt;span class="s2"&gt;])&lt;/span&gt;&lt;span class="se"&gt;\[\$&lt;/span&gt;&lt;span class="s2"&gt;txtrst&lt;/span&gt;&lt;span class="se"&gt;\]&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="sb"&gt;```&lt;/span&gt;
Here we are using &lt;span class="sb"&gt;`&lt;/span&gt;EXITCOL&lt;span class="sb"&gt;`&lt;/span&gt; to &lt;span class="nb"&gt;set &lt;/span&gt;red/white color deciding upon &lt;span class="k"&gt;return &lt;/span&gt;status and number of background &lt;span class="nb"&gt;jobs &lt;/span&gt;are displayed &lt;span class="k"&gt;in &lt;/span&gt;orange color.

Setting colors &lt;span class="k"&gt;in &lt;/span&gt;bash prompt is a bit lengthy process to explain, but &lt;span class="k"&gt;in &lt;/span&gt;short, you can copy-paste &lt;span class="o"&gt;[&lt;/span&gt;content of this file]&lt;span class="o"&gt;(&lt;/span&gt;https://github.com/chhajedji/dot-files/blob/master/T480/.bash/colors.sh&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;your &lt;span class="sb"&gt;`&lt;/span&gt;.bashrc&lt;span class="sb"&gt;`&lt;/span&gt; and add the required color within &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="se"&gt;\[&lt;/span&gt;&lt;span class="nv"&gt;$`&lt;/span&gt; and &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="se"&gt;\]&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; For example, &lt;span class="k"&gt;for &lt;/span&gt;regular green, you can use &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="se"&gt;\[&lt;/span&gt;&lt;span class="nv"&gt;$txtgrn&lt;/span&gt;&lt;span class="se"&gt;\]&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; Also don&lt;span class="s1"&gt;'t forget to reset the text after setting or else all text would appear in the applied color.

By this way of using colors, we can set various colors for different parts of prompt.

Screenshot highlighting different part after setting above prompt:

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qkefa3em0nvuz7t62nxc.png)

I like this shell prompt as it is minimal prompt displaying only useful information and also not eating up whole terminal space.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>shell</category>
      <category>bash</category>
      <category>linux</category>
      <category>terminal</category>
    </item>
    <item>
      <title>Add return of last command to your shell prompt </title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Sat, 20 Feb 2021 11:10:45 +0000</pubDate>
      <link>https://dev.to/chhajedji/add-return-of-last-command-to-your-shell-prompt-58mh</link>
      <guid>https://dev.to/chhajedji/add-return-of-last-command-to-your-shell-prompt-58mh</guid>
      <description>&lt;p&gt;Whenever we execute a shell command, it returns an integer value. When this value is &lt;code&gt;0&lt;/code&gt;, last command was a success. Any other number is the error code. We can see the return of last command by printing the value of &lt;code&gt;?&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;To test this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter command &lt;code&gt;ls&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Check it's return by command &lt;code&gt;echo $?&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Enter some random letters and press Enter&lt;/li&gt;
&lt;li&gt;Check return by &lt;code&gt;echo $?&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You should get an error in the second time when you enter some random command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chinmay@CC-T480:~/Desktop$ ls
file
chinmay@CC-T480:~/Desktop$ echo $?
0    &amp;lt;-- Success
chinmay@CC-T480:~/Desktop$ a
a: command not found
chinmay@CC-T480:~/Desktop$ echo $?
127  &amp;lt;-- Error code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will use this &lt;code&gt;$?&lt;/code&gt; value in our prompt to see if our last command has passed or failed.&lt;/p&gt;

&lt;p&gt;We also need to know about environment variable &lt;code&gt;PROMPT_COMMAND&lt;/code&gt;. Bash provides an environment variable called &lt;code&gt;PROMPT_COMMAND&lt;/code&gt;. The contents of this variable are executed as a regular Bash command just before Bash displays a prompt.&lt;/p&gt;

&lt;p&gt;Since our bash prompt should contain status of last command, it should be set inside &lt;code&gt;PROMPT_COMMAND&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;First we will write a simple shell function to update the prompt with return code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;exit_code&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;# Save the exit status of last command. This&lt;/span&gt;
    &lt;span class="c"&gt;# needs to be done first otherwise exit status of&lt;/span&gt;
    &lt;span class="c"&gt;# other commands will be stored in this variable.&lt;/span&gt;
    &lt;span class="nv"&gt;EXIT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="c"&gt;# PS1 needs to be reset or else it will&lt;/span&gt;
    &lt;span class="c"&gt;# be appended every time to previous one.&lt;/span&gt;
    &lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;

    &lt;span class="c"&gt;# This will be final prompt, whatever set earlier will be&lt;/span&gt;
    &lt;span class="c"&gt;# overwritten by this.&lt;/span&gt;
    &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$EXIT&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\w&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can add this function to our &lt;code&gt;PROMPT_COMMAND&lt;/code&gt;&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;# exit_code Should be first command in `PROMPT_COMMAND' to be executed or # else return status will always be 0/true as it will hold return status of&lt;/span&gt;
&lt;span class="c"&gt;# previous command.&lt;/span&gt;

&lt;span class="c"&gt;# First we check if prompt command is empty or not.&lt;/span&gt;
&lt;span class="c"&gt;# If empty, just add `exit_code' to it. If non empty,&lt;/span&gt;
&lt;span class="c"&gt;# make it `exit_code:$PROMPT_COMMAND'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PROMPT_COMMAND&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;PROMPT_COMMAND&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"exit_code;&lt;/span&gt;&lt;span class="nv"&gt;$PROMPT_COMMAND&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nv"&gt;PROMPT_COMMAND&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"exit_code"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding the above 2 snippets in your &lt;code&gt;.bashrc&lt;/code&gt;, you get something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chinmay@CC-T480:~$ exit_code() {
&amp;gt;     EXIT="$?"
&amp;gt;     PS1=""
&amp;gt;     export PS1="$EXIT \w $ "
&amp;gt; }
chinmay@CC-T480:~$ PROMPT_COMMAND="exit_code"
0 ~ $ ls Desktop/
file
0 ~ $ ^C
130 ~ $ a
a: command not found
127 ~ $ echo $?
127
0 ~ $ echo $?    # return of last echo command
0
0 ~ $ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the first number in our prompt is the return status of last command. For &lt;code&gt;ls&lt;/code&gt;, we see a &lt;code&gt;0&lt;/code&gt; as it ran as expected. When I ran command &lt;code&gt;a&lt;/code&gt;, bash threw an error saying &lt;code&gt;command not found&lt;/code&gt; and it's error code is &lt;code&gt;127&lt;/code&gt; which we can see in next line. For pressing &lt;code&gt;ctrl-c&lt;/code&gt;, we can see error code as &lt;code&gt;130&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Checkout &lt;a href="https://dev.to/chhajedji/minimal-and-super-useful-shell-prompt-1g8l"&gt;designing a minimal bash prompt&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
      <category>terminal</category>
      <category>linux</category>
    </item>
    <item>
      <title> Add background jobs to your shell prompt</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Sat, 20 Feb 2021 10:24:12 +0000</pubDate>
      <link>https://dev.to/chhajedji/background-jobs-add-to-your-shell-prompt-3eg2</link>
      <guid>https://dev.to/chhajedji/background-jobs-add-to-your-shell-prompt-3eg2</guid>
      <description>&lt;p&gt;If you know what are background processes, you can directly proceed to see Setting the prompt.&lt;/p&gt;

&lt;h3&gt;
  
  
  Background processes
&lt;/h3&gt;

&lt;p&gt;Whenever we execute a time taking command, we don't see the prompt till the time command finishes. For example, when we execute &lt;code&gt;sleep 5s&lt;/code&gt;, shell will do nothing for 5 seconds but wait for the command (&lt;code&gt;sleep&lt;/code&gt;) to finish. After 5 seconds, we will see the prompt again.&lt;/p&gt;

&lt;p&gt;Many times, commands are not worthy to wait till they finish their processing. For example, when you are compiling a project and it takes about a minute to complete. You can run the build in background by using &lt;code&gt;&amp;amp;&lt;/code&gt; at the end of command and you will be notified when background job is completed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chinmay@CC-T480:~$ sleep 5 &amp;amp;
[1] 3683711
chinmay@CC-T480:~$ # After 5 seconds when we press Enter
[1]+  Done                    sleep 5
chinmay@CC-T480:~$ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here what we did was put &lt;code&gt;sleep 5&lt;/code&gt; task in background and we got the background process ID that is &lt;code&gt;3683711&lt;/code&gt;. After 5 or more seconds when we enter a new command just press Enter, we see that the background job &lt;code&gt;sleep 5&lt;/code&gt; is completed by seeing &lt;code&gt;Done sleep 5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When building a project we can send the build process in background and while waiting for it to complete, we can do some other task. If we are using &lt;code&gt;make&lt;/code&gt; to build a project and it takes about a minute to complete, we can use &lt;code&gt;make &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/code&gt; to build in background and not display any info/error logs while also making the shell prompt usable to give other commands.&lt;/p&gt;

&lt;p&gt;We can also stop a process by hitting &lt;code&gt;Ctrl-Z&lt;/code&gt; and this will also send the task in background. But in this case, task will not run in background but will be stopped until resumed by command &lt;code&gt;fg&lt;/code&gt; in same terminal. We can see the background tasks by command &lt;code&gt;jobs&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;03:26:34 $ sleep 10
^Z
[1]+  Stopped                 sleep 10
03:26:36 $ jobs
[1]+  Stopped                 sleep 10
03:26:38 $ fg
sleep 10
03:26:45 $ jobs
03:26:47 $ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another common use of sending task to background is while using &lt;code&gt;vim&lt;/code&gt; or other terminal based editor. When we need to run some commands in terminal, we can just hit &lt;code&gt;ctrl-z&lt;/code&gt; in normal mode and &lt;code&gt;vim&lt;/code&gt; will be stopped. This way we can have our terminal prompt for running commands. When done with terminal, we can switch back to &lt;code&gt;vim&lt;/code&gt; by &lt;code&gt;fg&lt;/code&gt; command.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting the prompt
&lt;/h3&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bash prompt can be set by setting the environment variable &lt;code&gt;PS1&lt;/code&gt;. We will update this variable to get number of background jobs in our prompt.&lt;/p&gt;

&lt;p&gt;If we see manual page for &lt;code&gt;bash&lt;/code&gt;, we can see that it says we can use &lt;code&gt;\j&lt;/code&gt; to show number of jobs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\j     the number of jobs currently managed by the shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But most of the times we have 0 jobs running in background and displaying a 0 every time is not so tidy approach.&lt;/p&gt;

&lt;p&gt;We can use a simple bash command to print the jobs in the prompt if they are more than 0.&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="o"&gt;[&lt;/span&gt; &lt;span class="se"&gt;\j&lt;/span&gt; &lt;span class="nt"&gt;-gt&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\j&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;\j&lt;/code&gt; is the number of background jobs. What we are doing is checking if it's greater than 0, if yes, then print (&lt;code&gt;echo&lt;/code&gt;) in the prompt else not.&lt;/p&gt;

&lt;p&gt;A simple shell prompt including the current directory and number of background processes can be like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chinmay@CC-T480:~/Downloads$ PS1="\w\$([ \j -gt 0 ] &amp;amp;&amp;amp; echo [\j]) $ "
~/Downloads $ sleep 10
^Z
[1]+  Stopped                 sleep 10
~/Downloads[1] $ sleep 15
^Z
[2]+  Stopped                 sleep 15
~/Downloads[2] $ vi

[3]+  Stopped                 vi
~/Downloads[3] $ jobs
[1]   Stopped                 sleep 10
[2]-  Stopped                 sleep 15
[3]+  Stopped                 vi
~/Downloads[3] $ fg 2
sleep 15
~/Downloads[2] $ fg 1
sleep 10
~/Downloads[1] $ fg
vi
~/Downloads $ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the number of background processes will be listed inside square brackets.&lt;/p&gt;

&lt;p&gt;Checkout &lt;a href="https://dev.to/chhajedji/minimal-and-super-useful-shell-prompt-1g8l"&gt;designing a minimal bash prompt&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
      <category>linux</category>
      <category>terminal</category>
    </item>
    <item>
      <title> Add time stamp in your shell prompt </title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Sat, 20 Feb 2021 06:00:12 +0000</pubDate>
      <link>https://dev.to/chhajedji/add-time-stamp-in-your-shell-prompt-252c</link>
      <guid>https://dev.to/chhajedji/add-time-stamp-in-your-shell-prompt-252c</guid>
      <description>&lt;p&gt;Bash prompt can be set by setting the environment variable &lt;code&gt;PS1&lt;/code&gt;. We need to update this variable to get time in our prompt.&lt;/p&gt;

&lt;p&gt;There are 4 ways to get the time in prompt. If you see manual page for &lt;code&gt;bash&lt;/code&gt;, you can see time can be set using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the time is not the current time but the time when prompt was last updated. Prompt will be updated when previous command completed.&lt;/p&gt;

&lt;p&gt;Sample usage:&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="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;   &lt;span class="c"&gt;# 11:13:54 $ &lt;/span&gt;
&lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\T&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;   &lt;span class="c"&gt;# 11:14:01 $ &lt;/span&gt;
&lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\@&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;   &lt;span class="c"&gt;# 11:14 AM $ &lt;/span&gt;
&lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\A&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;   &lt;span class="c"&gt;# 11:14 $ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add whichever style you like to your &lt;code&gt;$HOME/.bashrc&lt;/code&gt; and every time you open a new terminal, you will see time in command prompt.&lt;/p&gt;

&lt;p&gt;If you wish to show current directory with time in prompt, a nice prompt setting could be like&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="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\w&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\A&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;PROMPT_DIRTRIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
&lt;span class="c"&gt;# Resulting in prompt to look like&lt;/span&gt;
&lt;span class="c"&gt;# ~/.../bluetooth/nimble 11:16 $ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;PROMPT_DIRTRIM&lt;/code&gt; would set the number of parent directories you wish to see in the prompt.&lt;/p&gt;

&lt;p&gt;Checkout &lt;a href="https://dev.to/chhajedji/minimal-and-super-useful-shell-prompt-1g8l"&gt;designing a minimal bash prompt&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
      <category>terminal</category>
      <category>linux</category>
    </item>
    <item>
      <title>Add current working directory in your shell prompt</title>
      <dc:creator>chinmay chhajed</dc:creator>
      <pubDate>Fri, 19 Feb 2021 18:33:23 +0000</pubDate>
      <link>https://dev.to/chhajedji/add-current-working-directory-in-your-shell-prompt-5fca</link>
      <guid>https://dev.to/chhajedji/add-current-working-directory-in-your-shell-prompt-5fca</guid>
      <description>&lt;p&gt;Bash prompt can be set by setting the environment variable &lt;code&gt;PS1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Current directory can be displayed in 3 types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full path
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/work/esp/esp-idf/examples/bluetooth/nimble$ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Partial path
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/.../bluetooth/nimble$ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Only parent directory.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nimble$ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In value of &lt;code&gt;PS1&lt;/code&gt;, &lt;code&gt;\w&lt;/code&gt; or &lt;code&gt;\W&lt;/code&gt; can be used to include working directory in the prompt. Change the value of &lt;code&gt;PS1&lt;/code&gt; in your &lt;code&gt;$HOME/.bashrc&lt;/code&gt; file to change it for every terminal.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you use &lt;code&gt;zsh&lt;/code&gt; or any other shell, search where the config file is located and update it accordingly. &lt;code&gt;.bashrc&lt;/code&gt; is used for &lt;code&gt;bash&lt;/code&gt; shell which is default in most systems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To set full path, &lt;code&gt;\w&lt;/code&gt; can be used.&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="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\w&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="c"&gt;# Prompt would look like:&lt;/span&gt;
&lt;span class="c"&gt;# ~/work/esp/esp-idf/examples/bluetooth/nimble$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see only current directory's name in prompt, use &lt;code&gt;\W&lt;/code&gt;&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="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\W&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="c"&gt;# Prompt would look like:&lt;/span&gt;
&lt;span class="c"&gt;# nimble$ &lt;/span&gt;
&lt;span class="nb"&gt;pwd&lt;/span&gt;
&lt;span class="c"&gt;# Prompt will show only first parent directory, current path is:&lt;/span&gt;
&lt;span class="c"&gt;# /home/chinmay/work/esp/esp-idf/examples/bluetooth/nimble&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see partial path, the environment variable &lt;code&gt;PROMPT_DIRTRIM&lt;/code&gt; can be set to desired value to see number of parent directories. Default value of &lt;code&gt;PROMPT_DIRTRIM&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt;.&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="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\w\$&lt;/span&gt;&lt;span class="s2"&gt; "&lt;/span&gt; &lt;span class="c"&gt;# Setting PS1 to show full path&lt;/span&gt;
&lt;span class="c"&gt;# ~/work/esp/esp-idf/examples/bluetooth/nimble$ &lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PROMPT_DIRTRIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4 &lt;span class="c"&gt;# Trimming path to 4 directories&lt;/span&gt;
&lt;span class="c"&gt;# ~/.../esp-idf/examples/bluetooth/nimble$ &lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PROMPT_DIRTRIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2 &lt;span class="c"&gt;# Trimming path to 2 directories&lt;/span&gt;
&lt;span class="c"&gt;# ~/.../bluetooth/nimble$ &lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PROMPT_DIRTRIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 &lt;span class="c"&gt;# Back to normal&lt;/span&gt;
&lt;span class="c"&gt;# ~/work/esp/esp-idf/examples/bluetooth/nimble$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checkout &lt;a href="https://dev.to/chhajedji/minimal-and-super-useful-shell-prompt-1g8l"&gt;designing a minimal bash prompt&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
      <category>linux</category>
      <category>terminal</category>
    </item>
  </channel>
</rss>
