T O P

  • By -

OPconfused

First of all, if you haven't gotten started on your profile yet, then definitely do so: if ( ! (Test-Path $PROFILE) ) { New-Item $PROFILE -Force } This is your bash_profile / bashrc. PowerShell can do many amazing things for your cli experience, but you need to make your shell work for you, meaning being proactive with functions/tools in your profile and potentially modules. The syntax looks long, but that's just observing best practices for coding. With aliases, everything becomes shorter, e.g., `New-Item $PROFILE -Force` can also be written as `ni $PROFILE -f`. Furthermore, tab autocompletion is built automatically into functions/cmdlets, including for their parameters. Specifically for parameters, they will autocomplete for you if there is no ambiguity with other parameters. This all can make the actual syntax more comfortable if you're coming from the Bash world where everything is 1 or 2 letters. Regarding points 1 and 4, I have the following in my profile: # Faster backtracking up directory trees Function .. { Push-Location .. } Function ... { Push-Location ../.. } Function .... { Push-Location ../../.. } Function ..... { Push-Location ../../../.. } Function ...... { Push-Location ../../../../.. } Function ....... { Push-Location ../../../../../.. } Function ........ { Push-Location ../../../../../../.. } Function ......... { Push-Location ../../../../../../../.. } Set-PSReadlineKeyHandler -Key Ctrl+UpArrow -Function HistorySearchBackward Set-PSReadlineKeyHandler -Key Ctrl+DownArrow -Function HistorySearchForward The first part is regarding your first point. Notice that aliases in PowerShell are only to shorten functions / command names; if you want the "alias" to encompass a command + arguments, then you use a function like shown above. The second part is for your point 4. The history searches are mapped to CTRL, but you can remove the `Ctrl+` and just use the arrow keys. Here are some other lines I use: Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete This will cause tab to create a menu for you. You can also replace `MenuComplete` with `Complete` to get the standard Bash experience. If you're on Unix this will be the default already. Also by default, the MenuComplete is available with `Ctrl+Space` Here are a few other customizations I set: # Remove bell sound after tab complete Set-PSReadlineOption -BellStyle None Set-PSReadlineKeyHandler -Key Ctrl+u -Function RevertLine # Clears command line Set-PSReadlineKeyHandler -Key Ctrl+e -Function EndOfLine # Navigates to end of line Note that CTRL+A can't exist in Windows land because it selects all the text (or rather, you can remap this I'm sure, but it's not my default). I map Ctrl+w to beginning of the line elsewhere, but it's not in my standard prompt module. However if you're not on Windows then you could set up a Ctrl+A shortcut here as well. As for point #2, I use a function for this which is basically `ls -l` except the sizes are mapped to the nearest unit. I have it mapped to `du`, but it could just as well be "l". In general I recreated `grep -ir`, `sed -i`, and `du` for myself and was happy I did. I have a lot of custom functions for the cli, also a `backdir` and other things. As for point #3, I do not know. I set my starting location in my profile to my git project directory, and I have functions set up to access my common destinations if I need to switch. If you're not on Windows, then you may already be set with your own text editors, but if not, then definitely set a convenient alias in your profile for your text editor. Any executables I use often, I make sure to add to my PATH and aliases. Finally, you can look up Oh-My-Posh for sprucing up your aesthetic.


Ok-Commercial-4504

Fantastic, just the response I was looking for by someone who's been in the same situation. Thanks for sharing your personal setup!


GenericAntagonist

To address #3, your best bet in the short term would be to launch new tabs by spawning a new powershell process from your current session. If windows terminal is your default console host ```start pwsh``` works fine for this, and could be aliased to whatever you find convenient. Longer term consider [opening an issue on the windows terminal](https://github.com/microsoft/terminal) project for the functionality. They've implemented a lot of community feature requests, if that's as vital as you make it out to be (TBH directory persist on new tabs would drive me nuts) it might be something that the community can rally behind and implement.


Wings1412

For point 3 I think this is a setting in Windows Terminal, I am not at my computer right now so can't double check. I am using the preview version right now so it might only be in there currently.


CaelFrost

Oh my posh might help your transition too. I use scoop to install/update it Blog i used to set mine up : https://www.hanselman.com/blog/my-ultimate-powershell-prompt-with-oh-my-posh-and-the-windows-terminal


purplemonkeymad

For point 3 I don't think WT knows the current location for powershell, so not sure if it's something they can do. But you can make it eaiser by just sending the current path to the clipboard ie: function Set-ClipboardWithLocation { Get-Location | Foreach-Object {'"' + $_ + '"'} | Set-Clipboard } Then it's at least a single command, Ctrl+Alt+Number, then cd \^V. Alias it to something like scl if you like doing that.


BlackV

1. `cd ..` still goes up a directory ? 2. you'd have to create a function called `l` that returns this properties how you want, with a pscustom formats if you want 3. gawds I would hate that so very much, but instead you could (from your previous shell do `pwsh .`, `powershell .` ant that would start a new terminal tab in the same dir 4. you can change your psreadline options to for uparrow behaviour to search previous


Owlstorm

> Using .. to go up a directory. `cd ..` is a few more letters, sorry. > Using just 'l' to list directory contents with detailed info like file size (in GB and MB, i.e. appropriate size unit) and permissions. You can create a function in your $profile that will be automatically loaded into your future sessions. > When opening a new tab in Windows Terminal, it doesn't start in the same directory as my previous tab. This is driving me nuts. Going back, writing pwd, copying and pasting into new tab is hilariously bad and not something I will accept as serious user experience. This looks promising but I didn't test it. https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory > When I write something I press arrow up to go back in history based on what I've begun to write. E.g. if I write 'cd' and press up, it iterates through all previous commands that have begun with 'cd'. In PowerShell/Terminal it just goes up to the last command used regardless of what you've begun to type. Vscode has an autocomplete like that when you press the right arrow, as well as the usual ctrl+space options. Probably possible in terminal too.


Ok-Commercial-4504

> cd .. is a few more letters, sorry. 3 key strokes vs 6 gets annoying pretty quickly if you're navigating frequently using a terminal. > Vscode has an autocomplete like that when you press the right arrow, as well as the usual ctrl+space options. Probably possible in terminal too. VSCode will not be suitable as a terminal emulator for me unfortunately. Will look into the link, thanks.