Powershell – find alias or function in profile by pattern

Since I have lots of aliases and functions in my profile, frequently I need to search them by some pattern.

This Powershell function lets me do just that.

function ff {
  param(
    [string]$Pattern
  )

  # Define the path to the PowerShell profile
  $profilePath = $PROFILE

  # Check if the profile exists
  if (-not (Test-Path $profilePath)) {
    Write-Host "Profile script does not exist at $profilePath"
    return
  }

  # Define the patterns to search for aliases and functions
  $patterns = "Set-Alias.*$Pattern", "New-Alias.*$Pattern", "function.*$Pattern"

  # Search the profile for the specified pattern
  # Select-String -Path $profilePath -Pattern $patterns
  Select-String -Path $profilePath $patterns
}

Now, all I need to do is type this to find the matching line and the actual function in my profile.

> ff <pattern>

Ruby OpenSSL::SSL::SSLError – SSL_connect returned=1 errno=0 unsafe legacy renegotiation disabled

So, all of a sudden, one of our servers, while trying to connect to another, started giving this cryptic error –

OpenSSL::SSL::SSLError - SSL_connect returned=1 errno=0 unsafe legacy renegotiation disabled

These kind of errors are usually dependent on some system updates. But the error seemed to be coming from the target server. After a bit of searching around, this article gave the most understandable information.

From that article –

This “unsafe legacy renegotiation disabled” error happens when connecting to outdated endpoints that do not support RFC 5746 secure renegotiation. Ideally, the endpoints causing these errors should be upgraded for security reasons. 

In the same article, they mention that it should be possible to remove this security check, but the solutions mentioned there didn’t work.

Continue reading

How to require multiple files in irb from command line

Recently, I had the need to run Ruby’s irb with multiple files already loaded.

After a bit of trial and error I came up with this which worked perfectly!

irb -r ./file1.rb -r ./dir/file2.rb

The files get loaded in order so if there are any dependencies in file2.rb on something in file1.rb, that works correctly.

Upgrading Wallabag (again!)

So, I upgraded my server to the latest Ubuntu release and Wallabag broke. I remember I had a tough time upgrading Wallabag. So this time, I decided to run it as a Docker container to avoid issues.

Unfortunately, this also had a few challenges!

Most of the stuff on my server run using flat files or SQLite databases, so I referred to the official Wallabag docs for running it on Docker. It gave the docker run command, but I wanted it as a docker-compose.yml file instead.

Continue reading

Disable browser caching in Ruby Roda app

Recently, writing a plain Roda app, I was facing a caching problem. I had a list and a detail page and whenever there was a list item clicked on I was using the flash plugin to maintain the item selected and highlighting the item when the list page was loaded.

However, on navigating back via the browser button, the cached page was showing up and the highlight would be on the previous selected item or not there at all.

Continue reading

fzf – error when pressing Ctrl+R

I’ve become a big fan of fzf since I discovered it.

However, after a recent upgrade, when I pressed Ctrl+R, I got the following error –

unknown option: --scheme=history

After some searching, found the following solution.

Remove fzf from /usr/bin/ and relink it.

Run these two commands in order –

sudo rm /usr/bin/fzf
sudo ln -s ~/.fzf/bin/fzf /usr/bin/fzf

Install fzf for Powershell on Windows

Since I installed fzf on Linux, I also wanted it in my Windows Powershell prompt.

To install fzf

winget install fzf

And then to get keyboard shortcuts working, following lines need to be added in the profile.ps1

Remove-PSReadlineKeyHandler 'Ctrl+r'
Remove-PSReadlineKeyHandler 'Ctrl+t'
Import-Module PSFzf

install fzf on Linux

fzf is a serious timesaver. To be able to quickly go through past commands and in a fuzzy manner, especially when you don’t recall the exact command is a Godsend!

To install fzf on Linux, we need to

a) clone the repository into the system

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf

b) run the command which will add the relevant shortcut keys

~/.fzf/install --all

There are a bunch of other stuff that can be done once fzf is installed. For example, to see instant file previews –

fzf --preview 'less {}'

And if there is bat also installed, then the previews can show syntax highlighting and line numbers also!

fzf --preview 'bat --color=always --style=numbers --line-range=:100 {}'

Copyright © 2024 the möbius trip

Theme by Anders NorenUp ↑