<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://nodewaveblog.vercel.app/feed.xsl"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="https://search.yahoo.com/mrss/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
          <atom:link href="https://nodewaveblog.vercel.app/tags/command-line/rss.xml" rel="self" type="application/rss+xml" />
        <atom:link href="https://nodewaveblog.vercel.app/tags/rss.xml" rel="up" type="application/rss+xml" title="Tags Directory Feed" />
        <atom:link href="https://nodewaveblog.vercel.app/rss.xml" rel="up" type="application/rss+xml" title="Master Root Feed" />
        <title>NodeWave — Tag: #command-line</title>
        <link>https://nodewaveblog.vercel.app/</link>
        <description>RSS feed for articles and development logs tagged under #command-line on NodeWave.</description>
        <lastBuildDate>Tue, 01 Dec 2026 21:40:05 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>Nodewave RSS Engine</generator>
        <language>en</language>
        <image>
            <title>NodeWave — Tag: #command-line</title>
            <url>https://nodewaveblog.vercel.app/logo.png</url>
            <link>https://nodewaveblog.vercel.app/</link>
        </image>
        <copyright>Copyright © 2026 NodeWave. All rights reserved.</copyright>
        <item>
            <title><![CDATA[Master Git Housekeeping - Auto-Pruning Dead Tracking Branches and Fixing Detached HEADs]]></title>
            <link>https://nodewaveblog.vercel.app/blogs/git-housekeeping</link>
            <guid isPermaLink="false">https://nodewaveblog.vercel.app/blogs/git-housekeeping</guid>
            <pubDate>Sat, 27 Jun 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[Clean up the debris after a massive local sync. Learn how to automatically drop deleted remote tracking branches and rescue your code from a detached HEAD state.]]></description>
            <content:encoded><![CDATA[<p>Once you automate your local branch syncs, you will quickly notice a secondary annoying problem: <strong>ghost branches</strong>.</p><p>Your teammates delete their feature branches on</p><p><a href="https://github.com/" rel="nofollow">GitHub</a></p><p>after pulling a pull request, but those references still clutter your local <code>git branch -a</code> view forever. Worse yet, if an automated script or manual checkout accidentally lands you on a raw commit identifier instead of a formal pointer, you will drop straight into the twilight zone known as a <strong>detached HEAD state</strong>.</p><p>Here is how to automate your repository cleanup and rescue your code when Git loses its coordinates.</p><h2 id="step-1-automate-stale-branch-pruning">Step 1: Automate Stale Branch Pruning</h2><p>By default, when you run <code>git fetch</code> or <code>git pull</code>, Git keeps your local tracking copies of remote branches even if someone deleted them from the main cloud server. Your local machine is left holding a graveyard of stale references.</p><p>You can manually clean them up using:</p><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sbgvK">git</span><span class="s_sjI"> fetch</span><span class="stzsN"> --prune
</span></span></code></pre><p>But you shouldn&apos;t have to remember to type that flag every single time.</p><h3 id="the-permanent-fix-run-this-global-configuration-command-to-instruct-git-to-automatically-sweep-away-dead-remote-branch-pointers-during-every-single-sync-operation">The Permanent Fix Run this global configuration command to instruct Git to automatically sweep away dead remote branch pointers during every single sync operation:</h3><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sbgvK">git</span><span class="s_sjI"> config</span><span class="stzsN"> --global</span><span class="s_sjI"> fetch.prune</span><span class="s39Yj"> true
</span></span></code></pre><p>Now, your project history list actively auto-cleans itself without manual intervention.</p><h2 id="step-2-demystifying-and-fixing-the-detached-head">Step 2: Demystifying and Fixing the &quot;Detached HEAD&quot;</h2><p>A detached HEAD state occurs when your terminal pointer (<code>HEAD</code>) is looking directly at a specific <strong>commit hash</strong> rather than a named local branch (like <code>main</code> or <code>feature-login</code>).</p><h3 id="how-you-usually-get-there-you-checked-out-a-raw-commit-to-inspect-old-code-git-checkout-7a1b3c2">How you usually get there:- You checked out a raw commit to inspect old code: <code>git checkout 7a1b3c2</code></h3><ul><li>You checked out a remote branch directly without creating a local copy: <code>git checkout origin/feature-x</code>- An automation script errored out mid-transition.</li></ul><h3 id="the-danger-zoneyou-can-still-write-code-modify-files-and-make-commits-while-in-a-detached-head-state-however-these-new-commits-are-not-attached-to-any-branch-if-you-switch-back-to-main-your-new-changes-will-vanish-into-the-background-leaving-them-open-to-being-permanently-deleted-by-gits-garbage-collector">The Danger ZoneYou can still write code, modify files, and make commits while in a detached HEAD state. However, <strong>these new commits are not attached to any branch</strong>. If you switch back to <code>main</code>, your new changes will vanish into the background, leaving them open to being permanently deleted by Git&apos;s garbage collector.</h3><h2 id="step-3-the-detached-head-rescue-mission">Step 3: The Detached HEAD Rescue Mission</h2><p>If you realize you made commits while detached, do not panic. Your work is completely safe if you follow these precise steps.</p><h3 id="scenario-a-you-havent-left-the-detached-state-yetif-your-terminal-currently-says-head-detached-at-simply-wrap-your-floating-commits-into-a-brand-new-branch-immediately">Scenario A: You haven&apos;t left the detached state yetIf your terminal currently says <code>HEAD detached at...</code>, simply wrap your floating commits into a brand new branch immediately:</h3><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sutJx"># Create a new branch and switch to it right now
</span></span><span class="line" line="2"><span class="sbgvK">git</span><span class="s_sjI"> checkout</span><span class="stzsN"> -b</span><span class="s_sjI"> feature-rescued-work
</span></span></code></pre><p>Git automatically anchors all your floating commits directly to this new branch name. You can now safely merge it back into your primary workflow.</p><h3 id="scenario-b-you-already-switched-branches-and-your-work-vanishedif-you-accidentally-switched-back-to-main-and-your-recent-work-disappeared-gits-commit-history-tool-git-log-wont-show-it-you-must-query-the-deep-internal-log-system">Scenario B: You already switched branches and your work &quot;vanished&quot;If you accidentally switched back to <code>main</code> and your recent work disappeared, Git&apos;s commit history tool (<code>git log</code>) won&apos;t show it. You must query the deep internal log system:</h3><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sbgvK">git</span><span class="s_sjI"> reflog
</span></span></code></pre><p>This outputs a master transaction history of everywhere your terminal pointer has moved:</p><pre class="language-text"><code>7a1b3c2 HEAD@{0}: checkout: moving from 9f3e4d5 to main
9f3e4d5 HEAD@{1}: commit: Added critical hotfix code in detached state
7a1b3c2 HEAD@{2}: checkout: moving to 7a1b3c2
</code></pre><ol><li>Find the commit hash where you wrote your work (in this case, <code>9f3e4d5</code>).2. Target that hash to build a formal rescue branch:</li></ol><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sbgvK">git</span><span class="s_sjI"> branch</span><span class="s_sjI"> feature-recovered-commits</span><span class="s_sjI"> 9f3e4d5
</span></span></code></pre><p>Your changes are successfully pulled from the void into a clean, permanent tracking pointer.</p><h2 id="wrapping-up">Wrapping Up</h2><p>Maintaining a pristine repository requires a blend of automated configurations and conceptual awareness. By enforcing automatic reference pruning and mastering the mechanics of the <code>reflog</code>, you ensure your developer workspace remains highly performant, predictable, and resilient against unexpected operational mistakes.</p>]]></content:encoded>
            <author>yebei@nodewave.net (Gideon Yebei)</author>
            <category domain="https://nodewaveblog.vercel.app/categories/terminal-and-shells">terminal-and-shells</category>
            <category domain="https://nodewaveblog.vercel.app/tags/git">Git</category>
            <category domain="https://nodewaveblog.vercel.app/tags/command-line">Command Line</category>
            <category domain="https://nodewaveblog.vercel.app/tags/devops">DevOps</category>
            <enclosure url="https://nodewaveblog.vercel.app/blogs/posts/git-cleanup/cover.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Safely Update All Local Git Branches At Once Without Breaking Your Working Tree]]></title>
            <link>https://nodewaveblog.vercel.app/blogs/git-pull-all</link>
            <guid isPermaLink="false">https://nodewaveblog.vercel.app/blogs/git-pull-all</guid>
            <pubDate>Fri, 26 Jun 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[Stop manual checkouts. Learn why your naive git pull loops fail and discover the correct, automation-friendly way to fast-forward all local tracking branches at once.]]></description>
            <content:encoded><![CDATA[<p>Picture this scenario. You return to a massive project repository after a long weekend. Dozens of team branches have updated on GitHub, and your local workspace feels incredibly left behind.</p><p>Naturally, you decide to write a quick, clever shell script line to pull everything down at once:</p><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sVHd0">for</span><span class="su5hD"> branch </span><span class="sVHd0">in</span><span class="s_hVV"> \(</span><span class="sP7_E">(</span><span class="sbgvK">git</span><span class="s_sjI"> branch</span><span class="stzsN"> -r</span><span class="s_hVV"> \v</span><span class="s_sjI">ert{}</span><span class="s_sjI"> grep</span><span class="stzsN"> -v</span><span class="sjJ54"> &apos;</span><span class="s_sjI">\-&gt;</span><span class="sjJ54">&apos;</span><span class="sP7_E">);</span><span class="sVHd0"> do</span><span class="sbgvK"> git</span><span class="s_sjI"> pull</span><span class="s_hVV">\)</span><span class="s_sjI">branch</span><span class="sP7_E">;</span><span class="sVHd0"> done
</span></span></code></pre><p>You hit Enter, expecting a beautifully synced repository. Instead, your console explodes into a mess of syntax errors, detached HEAD states, and unexpected merge conflicts.</p><p>Here is why your native <code>git pull</code> loops are broken, how to fix them, and the ultimate safe alternative.</p><h2 id="why-the-naive-script-breaks-your-repo">Why The Naive Script Breaks Your Repo</h2><p>To understand why the loop above fails, you have to look closely at how <code>git pull</code> operates under the hood. The command relies on two distinct expectations:</p><ol><li><strong>Active Checkouts Only:</strong> <code>git pull</code> is explicitly designed to download remote changes and immediately merge them into your <em>currently checked-out</em> local branch. It is physically incapable of updating separate background branches.</li><li><strong>Argument Syntax:</strong> <code>git branch -r</code> outputs remote tracking references prefixed with the remote identifier (e.g., <code>origin/feature-auth</code>). Passing <code>origin/feature-auth</code> directly to a <code>git pull</code> command breaks structural syntax.</li></ol><p>If you run this inside your <code>main</code> branch, the loop will continuously try to force-merge <em>every single remote branch</em> into your clean <code>main</code> history.</p><h2 id="the-instant-fix-trust-git-fetch-all">The Instant Fix: Trust <code>git fetch --all</code></h2><p>Before writing custom automation scripts, remember that you rarely need to explicitly run a <code>git pull</code> on branches you aren&apos;t currently coding on.</p><p>If you simply want to download the latest state of the entire project to inspect histories or check things out later, run this native command:</p><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sbgvK">git</span><span class="s_sjI"> fetch</span><span class="stzsN"> --all
</span></span></code></pre><h3 id="why-this-is-your-best-default">Why this is your best default:</h3><ul><li><strong>Zero Risk:</strong> It downloads the raw remote objects and updates remote tracking pointers (like <code>origin/main</code>) without modifying your current workspace files.</li><li><strong>No Merge Conflicts:</strong> It will never accidentally force a broken merge or pollute your active staging index.</li><li><strong>Server Friendly:</strong> It makes a single optimized network request instead of hitting your server individually for every branch reference.</li></ul><hr /><h2 id="building-the-automated-local-multi-pull-script">Building the Automated Local Multi-Pull Script</h2><p>If you truly need every single <strong>local</strong> branch to immediately step forward and match its remote counterpart, you must explicitly force Git to safely navigate between branches.</p><p>Open a new shell script or your <code>.bashrc</code>/<code>.zshrc</code> file and add this robust layout:</p><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sutJx">#!/bin/bash
</span></span><span class="line" line="2"><span emptyLinePlaceholder>
</span></span><span class="line" line="3"><span class="sutJx"># 1. Stash any uncommitted workspace changes so they aren&apos;t lost
</span></span><span class="line" line="4"><span class="su5hD">has_changes</span><span class="smGrS">=</span><span class="s_hVV">\$</span><span class="sP7_E">(</span><span class="sbgvK">git</span><span class="s_sjI"> status</span><span class="stzsN"> --porcelain</span><span class="sP7_E">)
</span></span><span class="line" line="5"><span class="sVHd0">if</span><span class="sP7_E"> [</span><span class="smGrS"> -n</span><span class="sjJ54"> &quot;</span><span class="s_hVV">\$</span><span class="s_sjI">has_changes</span><span class="sjJ54">&quot;</span><span class="sP7_E"> ];</span><span class="sVHd0"> then
</span></span><span class="line" line="6"><span class="sptTA">    echo</span><span class="sjJ54"> &quot;</span><span class="s_sjI">Saving uncommitted work to stash...</span><span class="sjJ54">&quot;
</span></span><span class="line" line="7"><span class="sbgvK">    git</span><span class="s_sjI"> stash</span><span class="stzsN"> -u
</span></span><span class="line" line="8"><span class="sVHd0">fi
</span></span><span class="line" line="9"><span emptyLinePlaceholder>
</span></span><span class="line" line="10"><span class="sutJx"># 2. Save your current branch name to return safely later
</span></span><span class="line" line="11"><span class="su5hD">current_branch</span><span class="smGrS">=</span><span class="s_hVV">\$</span><span class="sP7_E">(</span><span class="sbgvK">git</span><span class="s_sjI"> rev-parse</span><span class="stzsN"> --abbrev-ref</span><span class="s_sjI"> HEAD</span><span class="sP7_E">)
</span></span><span class="line" line="12"><span emptyLinePlaceholder>
</span></span><span class="line" line="13"><span class="sutJx"># 3. Safely loop through clean local branch lists
</span></span><span class="line" line="14"><span class="sVHd0">for</span><span class="su5hD"> branch </span><span class="sVHd0">in</span><span class="s_hVV"> \$</span><span class="sP7_E">(</span><span class="sbgvK">git</span><span class="s_sjI"> for-each-ref</span><span class="stzsN"> --format=</span><span class="sjJ54">&apos;</span><span class="s_sjI">%(refname:short)</span><span class="sjJ54">&apos;</span><span class="s_sjI"> refs/heads/</span><span class="sP7_E">);</span><span class="sVHd0"> do
</span></span><span class="line" line="15"><span class="sptTA">    echo</span><span class="sjJ54"> &quot;</span><span class="s_sjI">Checking out </span><span class="s_hVV">\$</span><span class="s_sjI">branch...</span><span class="sjJ54">&quot;
</span></span><span class="line" line="16"><span class="sbgvK">    git</span><span class="s_sjI"> checkout</span><span class="sjJ54"> &quot;</span><span class="s_hVV">\$</span><span class="s_sjI">branch</span><span class="sjJ54">&quot;</span><span class="smGrS"> 2&gt;</span><span class="s_sjI">/dev/null
</span></span><span class="line" line="17"><span emptyLinePlaceholder>
</span></span><span class="line" line="18"><span class="sutJx">    # Use fast-forward only to avoid generating messy, unnecessary merge commits
</span></span><span class="line" line="19"><span class="sptTA">    echo</span><span class="sjJ54"> &quot;</span><span class="s_sjI">Applying remote fast-forward updates...</span><span class="sjJ54">&quot;
</span></span><span class="line" line="20"><span class="sbgvK">    git</span><span class="s_sjI"> pull</span><span class="stzsN"> --ff-only
</span></span><span class="line" line="21"><span class="sVHd0">done
</span></span><span class="line" line="22"><span emptyLinePlaceholder>
</span></span><span class="line" line="23"><span class="sutJx"># 4. Return to your starting point and restore work
</span></span><span class="line" line="24"><span class="sbgvK">git</span><span class="s_sjI"> checkout</span><span class="sjJ54"> &quot;</span><span class="s_hVV">\$</span><span class="s_sjI">current_branch</span><span class="sjJ54">&quot;</span><span class="smGrS"> 2&gt;</span><span class="s_sjI">/dev/null
</span></span><span class="line" line="25"><span class="sVHd0">if</span><span class="sP7_E"> [</span><span class="smGrS"> -n</span><span class="sjJ54"> &quot;</span><span class="s_hVV">\$</span><span class="s_sjI">has_changes</span><span class="sjJ54">&quot;</span><span class="sP7_E"> ];</span><span class="sVHd0"> then
</span></span><span class="line" line="26"><span class="sptTA">    echo</span><span class="sjJ54"> &quot;</span><span class="s_sjI">Restoring your original uncommitted changes...</span><span class="sjJ54">&quot;
</span></span><span class="line" line="27"><span class="sbgvK">    git</span><span class="s_sjI"> stash</span><span class="s_sjI"> pop
</span></span><span class="line" line="28"><span class="sVHd0">fi
</span></span><span class="line" line="29"><span emptyLinePlaceholder>
</span></span><span class="line" line="30"><span class="sptTA">echo</span><span class="sjJ54"> &quot;</span><span class="s_sjI">✨ All local branches synced successfully!</span><span class="sjJ54">&quot;
</span></span></code></pre><h3 id="key-upgrades-in-this-script">Key upgrades in this script:</h3><ul><li><strong>Stash Safety Net:</strong> It actively checks for uncommitted edits and temporarily shelves them so your checkout transitions don&apos;t error out.</li><li><strong>Fast-Forward Restrictions:</strong> Using <code>--ff-only</code> ensures that if a local branch has split or drifted too far from the remote history, the script will gracefully skip it rather than creating an automated merge mess.</li></ul><hr /><h2 id="convert-this-into-a-permanent-git-alias">Convert This Into a Permanent Git Alias</h2><p>Typing out long Bash scripts every time you open a project gets exhausting. Let&apos;s register this tool directly into your core Git configuration so it is accessible globally.</p><p>Open your global git configuration file:</p><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sbgvK">git</span><span class="s_sjI"> config</span><span class="stzsN"> --global</span><span class="stzsN"> --edit
</span></span></code></pre><p>Find the <code>[alias]</code> block and add a new custom command named <code>pull-all</code>:</p><pre class="language-ini shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span>[alias]
</span></span><span class="line" line="2"><span>    pull-all = &quot;!f() { \
</span></span><span class="line" line="3"><span>        curr=\$(git rev-parse --abbrev-ref HEAD); \
</span></span><span class="line" line="4"><span>        for b in \$(git for-each-ref --format=&apos;%(refname:short)&apos; refs/heads/); do \
</span></span><span class="line" line="5"><span>            git checkout \$b &amp;&amp; git pull --ff-only; \
</span></span><span class="line" line="6"><span>        done; \
</span></span><span class="line" line="7"><span>        git checkout \$curr; \
</span></span><span class="line" line="8"><span>    }; f&quot;
</span></span></code></pre><p>Save and exit. Now, clean updates across your entire workspace are compressed into a single elegant command:</p><pre class="language-bash shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span class="sbgvK">git</span><span class="s_sjI"> pull-all
</span></span></code></pre><h2 id="wrapping-up">Wrapping Up</h2><p>Automating your terminal flow should never come at the expense of your repository&apos;s stability. By switching from a raw <code>git pull</code> loop to an intentional, state-aware layout or leveraging <code>git fetch --all</code>, you keep your workflows smooth, fast, and entirely conflict-free.</p>]]></content:encoded>
            <author>yebei@nodewave.net (Gideon Yebei)</author>
            <category domain="https://nodewaveblog.vercel.app/categories/terminal-and-shells">terminal-and-shells</category>
            <category domain="https://nodewaveblog.vercel.app/tags/git">Git</category>
            <category domain="https://nodewaveblog.vercel.app/tags/command-line">Command Line</category>
            <category domain="https://nodewaveblog.vercel.app/tags/devops">DevOps</category>
            <enclosure url="https://nodewaveblog.vercel.app/blogs/posts/git-pull-all/cover.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Bash-ify Your PowerShell - The Ultimate Guide to Autosuggestions, Completions, and Subcommands]]></title>
            <link>https://nodewaveblog.vercel.app/blogs/powershell-bash</link>
            <guid isPermaLink="false">https://nodewaveblog.vercel.app/blogs/powershell-bash</guid>
            <pubDate>Tue, 16 Jun 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[Learn how to make PowerShell look, feel, and behave exactly like a premium Bash/Zsh environment with autosuggestions, interactive subcommand completions, and fuzzy history search.]]></description>
            <content:encoded><![CDATA[<p>Learn how to make PowerShell look, feel, and behave exactly like a premium Bash/Zsh environment with autosuggestions, interactive subcommand completions, and fuzzy history search.</p><p>Let’s be honest. If you are coming from a Linux or macOS background, opening up a raw PowerShell (<code>pwsh</code>) terminal can feel a bit like stepping into a parallel universe where everything is <em>almost</em> familiar, but just clunky enough to drive you crazy.</p><p>You miss the instant, predictive text of <code>fish</code>, the robust history search of <code>zsh</code>, and the effortless subcommand completions of a well-tuned <code>bash</code> setup. Out of the box, PowerShell’s tab-completion feels slow, and its visual feedback is... lacking.</p><p>But here is the secret: <strong>PowerShell is secretly an absolute powerhouse of customizability.</strong> With a few modern modules and a slick profile configuration, you can make <code>pwsh</code> look, feel, and behave exactly like a premium Bash/Zsh environment—all while retaining PowerShell&apos;s insane object-oriented pipeline capabilities.</p><p>Here is how to build the ultimate Bash-ified PowerShell experience.</p><h2 id="step-1-fix-the-keybindings-and-enable-fish-style-autosuggestions">Step 1: Fix the Keybindings and Enable Fish-Style Autosuggestions</h2><p>The foundation of a good Bash experience is how the line editor behaves. PowerShell handles this via a built-in module called <strong>PSReadLine</strong>. We just need to wake it up and give it the right instructions.</p><p>First, open your PowerShell profile in your favorite editor (e.g., VS Code):</p><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span>code $PROFILE
</span></span></code></pre><p><em>(If the file doesn&apos;t exist yet, run <code>New-Item -Path $PROFILE -Type File -Force</code></em> <em>first).</em></p><p>Now, paste these essential configurations into your profile:</p><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span># Set Bash-like Emacs keybindings (Ctrl+A to start of line, Ctrl+E to end, etc.)
</span></span><span class="line" line="2"><span>Set-PSReadLineOption -EditMode Emacs
</span></span><span class="line" line="3"><span emptyLinePlaceholder>
</span></span><span class="line" line="4"><span># Enable Fish-like inline predictive text history
</span></span><span class="line" line="5"><span>Set-PSReadLineOption -PredictionSource History
</span></span><span class="line" line="6"><span emptyLinePlaceholder>
</span></span><span class="line" line="7"><span># Change the prediction view to &quot;ListView&quot; or &quot;InlineView&quot; (Arrow keys to navigate)
</span></span><span class="line" line="8"><span>Set-PSReadLineOption -PredictionViewStyle InlineView
</span></span><span class="line" line="9"><span emptyLinePlaceholder>
</span></span><span class="line" line="10"><span># Set the color of the predictive text to be a subtle gray
</span></span><span class="line" line="11"><span>Set-PSReadLineOption -Colors @{ InlinePrediction = &apos;#666666&apos; }
</span></span><span class="line" line="12"><span emptyLinePlaceholder>
</span></span><span class="line" line="13"><span># Bind the Right Arrow key to accept the current inline suggestion
</span></span><span class="line" line="14"><span>Set-PSReadLineKeyHandler -Chord &apos;RightArrow&apos; -Function AcceptSuggestion
</span></span><span class="line" line="15"><span emptyLinePlaceholder>
</span></span><span class="line" line="16"><span># Bind Ctrl+Space to trigger standard menu completion (Zsh style)
</span></span><span class="line" line="17"><span>Set-PSReadLineKeyHandler -Chord &apos;Ctrl+Space&apos; -Function MenuComplete
</span></span></code></pre><h3 id="what-this-gives-you">What this gives you:</h3><ul><li><strong>Inline History Predictions:</strong> As you type, <code>pwsh</code> will look through your command history and visually suggest the rest of the command in gray text. Press the <strong>Right Arrow</strong> to accept it.</li><li><strong>Zsh-style Menus:</strong> Hit <code>Ctrl + Space</code> to open an interactive grid menu of all available completions right in your terminal buffer.</li></ul><h2 id="step-2-supercharge-subcommand-completions-with-carapace">Step 2: Supercharge Subcommand Completions with Carapace</h2><p>Standard PowerShell only knows how to tab-complete standard cmdlet arguments (like <code>-Path</code> or <code>-Credential</code>). If you type <code>git che[TAB]</code>, it stares at you blankly.</p><p>To get full subcommand completion for hundreds of CLI tools (<code>git</code>, <code>docker</code>, <code>kubectl</code>, <code>npm</code>, <code>gh</code>, <code>gcloud</code>), we are going to use <strong>Carapace-bin</strong>, the absolute gold standard for multi-shell command completion.</p><ol><li>Install Carapace using a package manager like Scoop or Winget:</li></ol><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span>winget install rsteube.carapace
</span></span></code></pre><ol start="2"><li>Add the initialization logic to your <code>$PROFILE</code>:</li></ol><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span># Initialize Carapace completions for PowerShell
</span></span><span class="line" line="2"><span># This hooks into the native engine to provide rich subcommand completions
</span></span><span class="line" line="3"><span>if (Get-Command carapace -ErrorAction SilentlyContinue) {
</span></span><span class="line" line="4"><span>    $old_executioncontext = $ExecutionContext
</span></span><span class="line" line="5"><span>    carapace _powershell | Out-String | Invoke-Expression
</span></span><span class="line" line="6"><span>}
</span></span></code></pre><p>Now, try typing <code>git</code> followed by <code>Ctrl + Space</code>. You will see an interactive menu showing options like <code>checkout</code>, <code>commit</code>, <code>clone</code>, complete with help descriptions for every single subcommand!</p><h2 id="step-3-add-fuzzy-history-searching-fzf">Step 3: Add Fuzzy History Searching (FZF)</h2><p>If you&apos;ve ever used <code>Ctrl + R</code> in Bash to reverse-search your history using a fuzzy finder, you know you can&apos;t live without it. We can bring this exact feature to PowerShell using the <code>PSFzf</code> module.</p><ol><li>Install the <code>fzf</code> binary and the PowerShell wrapper module:</li></ol><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span>winget install junegunn.fzf
</span></span><span class="line" line="2"><span>Install-Module PSFzf -Scope CurrentUser -Force
</span></span></code></pre><ol start="2"><li>Add this to your <code>$PROFILE</code>:</li></ol><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span>Import-Module PSFzf
</span></span><span class="line" line="2"><span># Overrides Ctrl+R to use the fuzzy finder for your PowerShell history
</span></span><span class="line" line="3"><span>Set-PSReadLineKeyHandler -Chord &apos;Ctrl+r&apos; -ScriptBlock { [PSFzf]::PostContextHistoryFzf() }
</span></span></code></pre><h2 id="step-4-inject-essential-bash-aliases-functions">Step 4: Inject Essential Bash Aliases &amp; Functions</h2><p>PowerShell has a few built-in aliases like <code>ls</code> and <code>rm</code>, but they map directly to PowerShell cmdlets (<code>Get-ChildItem</code>, <code>Remove-Item</code>), which don&apos;t accept standard Linux flags like <code>-la</code> or <code>-rf</code>.</p><p>Let&apos;s clean that up by introducing native functions that mirror standard Unix behavior:</p><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span># Quick directory listings that accept traditional arguments
</span></span><span class="line" line="2"><span>function ll { Get-ChildItem -Path . -Force | Out-Host }
</span></span><span class="line" line="3"><span>function la { Get-ChildItem -Path . -Force -Recurse | Out-Host }
</span></span><span class="line" line="4"><span emptyLinePlaceholder>
</span></span><span class="line" line="5"><span># A quick wrapper to make &apos;grep&apos; behave beautifully
</span></span><span class="line" line="6"><span>function grep ($pattern) { Select-String -Pattern $pattern }
</span></span><span class="line" line="7"><span emptyLinePlaceholder>
</span></span><span class="line" line="8"><span># Ensure sudo behavior exists via &apos;gsudo&apos; (install via winget install gerardog.gsudo)
</span></span><span class="line" line="9"><span>if (Get-Command gsudo -ErrorAction SilentlyContinue) {
</span></span><span class="line" line="10"><span>    Set-Alias -Name sudo -Value gsudo
</span></span><span class="line" line="11"><span>}
</span></span><span class="line" line="12"><span emptyLinePlaceholder>
</span></span><span class="line" line="13"><span># Quick navigation shortcuts
</span></span><span class="line" line="14"><span>function .. { Set-Location .. }
</span></span><span class="line" line="15"><span>function ... { Set-Location ..\.. }
</span></span></code></pre><h2 id="step-5-put-it-all-together-your-master-profile">Step 5: Put It All Together (Your Master Profile)</h2><p>Here is your complete, optimized <code>$PROFILE</code>. Copy this layout, save the file, and restart your terminal to activate your brand new, incredibly fast Bash-ified environment:</p><pre class="language-powershell shiki shiki-themes material-theme-lighter github-light github-dark" style=""><code><span class="line" line="1"><span># ==========================================
</span></span><span class="line" line="2"><span># 1. PSREADLINE CONFIG (Autosuggestions &amp; Keybindings)
</span></span><span class="line" line="3"><span># ==========================================
</span></span><span class="line" line="4"><span>Import-Module PSReadLine
</span></span><span class="line" line="5"><span>Set-PSReadLineOption -EditMode Emacs
</span></span><span class="line" line="6"><span>Set-PSReadLineOption -PredictionSource History
</span></span><span class="line" line="7"><span>Set-PSReadLineOption -PredictionViewStyle InlineView
</span></span><span class="line" line="8"><span>Set-PSReadLineOption -Colors @{ InlinePrediction = &apos;#666666&apos; }
</span></span><span class="line" line="9"><span emptyLinePlaceholder>
</span></span><span class="line" line="10"><span># Intuitive Navigation
</span></span><span class="line" line="11"><span>Set-PSReadLineKeyHandler -Chord &apos;RightArrow&apos; -Function AcceptSuggestion
</span></span><span class="line" line="12"><span>Set-PSReadLineKeyHandler -Chord &apos;Ctrl+Space&apos; -Function MenuComplete
</span></span><span class="line" line="13"><span emptyLinePlaceholder>
</span></span><span class="line" line="14"><span># Up/Down Arrows search history matching what you&apos;ve already typed
</span></span><span class="line" line="15"><span>Set-PSReadLineKeyHandler -Chord &apos;UpArrow&apos; -Function HistorySearchBackward
</span></span><span class="line" line="16"><span>Set-PSReadLineKeyHandler -Chord &apos;DownArrow&apos; -Function HistorySearchForward
</span></span><span class="line" line="17"><span emptyLinePlaceholder>
</span></span><span class="line" line="18"><span># ==========================================
</span></span><span class="line" line="19"><span># 2. SUBCOMMAND COMPLETIONS (Carapace Engine)
</span></span><span class="line" line="20"><span># ==========================================
</span></span><span class="line" line="21"><span>if (Get-Command carapace -ErrorAction SilentlyContinue) {
</span></span><span class="line" line="22"><span>    carapace _powershell | Out-String | Invoke-Expression
</span></span><span class="line" line="23"><span>}
</span></span><span class="line" line="24"><span emptyLinePlaceholder>
</span></span><span class="line" line="25"><span># ==========================================
</span></span><span class="line" line="26"><span># 3. FUZZY HISTORY MATCHING (FZF)
</span></span><span class="line" line="27"><span># ==========================================
</span></span><span class="line" line="28"><span>if (Get-Module -ListAvailable -Name PSFzf) {
</span></span><span class="line" line="29"><span>    Import-Module PSFzf
</span></span><span class="line" line="30"><span>    Set-PSReadLineKeyHandler -Chord &apos;Ctrl+r&apos; -ScriptBlock { [PSFzf]::PostContextHistoryFzf() }
</span></span><span class="line" line="31"><span>}
</span></span><span class="line" line="32"><span emptyLinePlaceholder>
</span></span><span class="line" line="33"><span># ==========================================
</span></span><span class="line" line="34"><span># 4. BASH ALIASES &amp; UTILITIES
</span></span><span class="line" line="35"><span># ==========================================
</span></span><span class="line" line="36"><span>function ll { Get-ChildItem -Force }
</span></span><span class="line" line="37"><span>function grep ($pattern) { $Input | Select-String -Pattern $pattern }
</span></span><span class="line" line="38"><span>if (Get-Command gsudo -ErrorAction SilentlyContinue) { Set-Alias -Name sudo -Value gsudo }
</span></span><span class="line" line="39"><span>function .. { Set-Location .. }
</span></span><span class="line" line="40"><span emptyLinePlaceholder>
</span></span><span class="line" line="41"><span>Write-Host &quot;🚀 PowerShell environment loaded with Bash-UX engine.&quot; -ForegroundColor Cyan
</span></span></code></pre>]]></content:encoded>
            <author>yebei@nodewave.net (Gideon Yebei)</author>
            <category domain="https://nodewaveblog.vercel.app/categories/terminal-and-shells">terminal-and-shells</category>
            <category domain="https://nodewaveblog.vercel.app/tags/powershell">PowerShell</category>
            <category domain="https://nodewaveblog.vercel.app/tags/command-line">Command Line</category>
            <category domain="https://nodewaveblog.vercel.app/tags/devops">DevOps</category>
            <enclosure url="https://nodewaveblog.vercel.app/blogs/posts/powershell-bash/cover.png" length="0" type="image/png"/>
        </item>
    </channel>
</rss>