Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Tuesday, July 1, 2025

Add ‘Open Bash Here’ into Visual Studio

 With the rise of cross-platform development, the need for Linux tools like bash has become more prevalent, even in Windows environments. Developers often need to run bash scripts for tasks such as deploying services to Azure or managing containers. An integrated bash prompt in Visual Studio, opening directly at a file’s location, can significantly streamline this process. Here we create a script amd config.VS to run it


Why

In a mixed development environment where Windows and Linux tools are both essential, there’s a challenge: Windows uses a different file path structure compared to Linux. When developing on Windows with Visual Studio but needing to run Linux-based tools (like bash scripts), there’s a disconnect — the paths don’t translate automatically between systems. This is where a Linux script comes into play.


Creating the script

To bridge this gap, we created a Linux script that performs path translation. It takes a Windows file path as input, converts it into a Linux-friendly path, and then opens a bash shell at that location.


vi ~/.open-wsl-bash.sh


#!/bin/bash

win_path=$1

# Replace single backslashes with double backslashes

win_path=${win_path//\\//\\\\}

# Translate the Windows path to WSL path

wsl_path=$(wslpath -u "$win_path")

# Navigate to the directory and open bash

cd "$wsl_path" && exec bash

Script Breakdown

#!/bin/bash: Shebang line to indicate the script uses bash.

win_path=$1: Assigns the first argument passed to the script to win_path.

win_path=${win_path//\\//\\\\}: Doubles the backslashes to escape them properly for bash.

wsl_path=$(wslpath -u "$win_path"): Uses wslpath to convert the Windows path to a WSL path.

cd "$wsl_path" && exec bash: Changes to the directory and opens a new bash shell.

This script is an essential piece of the puzzle for a seamless development experience across Windows and WSL environments.


Adding the External Command in Visual Studio

Find the path to wt.exe.

Navigate to Tools > External Tools.

Click “Add” and configure:

Title: Open Bash Here

Command: Path to your wt.exe.

Arguments: --profile "Ubuntu-20.04" -- bash -c "bash ~/.open-wsl-bash.sh '$(ItemDir)'"

Initial directory: $(ItemDir)

Visual Studio: Adding external command

“Ubuntu-20.04” is the name of my Linux Windows Terminal profile. Change it to your Linux profile name.



Conclusion

With this setup, you’ll have a seamless “Open Bash Here” command in Visual Studio that improves the development workflow by providing quick access to a Linux bash environment at the location of your current file.




Sunday, June 18, 2023

How to Manage and Clear Google Drive Storage : Find large files and Folders

  

Manage Google Drive Storage

Clean Up / Remove Large Files :

1.       1 Review Storage Usage:

2.      2 Find and Remove Large Files

3.       3 Find and Remove Large and Medium Sizes Files.

4.       4 Search and Bulk Delete Large Emails:

5.      5 Find and Bulk Delete LARGE Photos           

6.      6 Find and Remove LARGE OLD files Shared with You


Clean Up / Remove Large Folders

1.       1: View LARGE Folders: Install THIS Freemium Google Drive Explorer App:

a.       How To View Folder Size Google Drive – Using Add-On [Working]

b.       Ganapthy has written an add-on which can be found in the Google Workspace Marketplace for free. It can be used to do different functions on Google Drive. Especially checking the Google Drive size of the folder

 

2.       2. Free Apps to View Folder Sizes:

a.       How to see the folders size in Google Drive | Without using any software | Google Colab

                                                               i.      Want to know how to see the size of folders in google drive or folders which are inside parent folders. This video is exactly for same and we'll see how to find out folders size without downloading any external software with the use of Google Colab in this video

                                                             ii.      Using this : app:

                                                           iii.      Sample Results

Sunday, May 1, 2022

Get Powershell Version : various methods to get the version of Powershell

 There are numerous ways to do the same thing in Powershell. In this post, we will go over every way to check the PowerShell version.  All these ways should work in both Windows PowerShell and PowerShell Core. 


Here are the ways to get the version of PowerShell :

  • The $host.Version property
  • The (Get-Host).Version property
  • The $PSVersionTable.PSVersion property
  • The registry (Windows PowerShell only)

Another method is getting the Powershell version from a remote computer:

Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock {Get-Host} -Credential $cred

results in for example:

Major Minor Build Revision PSComputerName ----- ----- ----- -------- -------------- 1 0 0 0 10.0.0.5


Using $host and Get-Host  command

: Referencing $host.Version is another way to check Powershell version. The $host variable is an automatic variable that returns the same output as Get-Host.



























$host.Version on Remote Computers

You will see the same behavior via PowerShell Remoting with $host.Version as you will running Get-Host.

Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock {$host.Version} -Credential $cred


Registry

If you don’t want to open up PowerShell itself, you can also check the registry. The version of PowerShell is tucked away under a value in the registry key path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine. This registry key has a value called PowerShellVersion that you can reference by using Get-ItemProperty.

(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion 5.1.17134.1

Also WMI:

reg query HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine /v PowerShellVersion HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine PowerShellVersion REG_SZ 5.1.17134.1


Registry on a remote computer:

$scriptBlock = { [version](Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion } PS51> Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock $scriptBlock -Credential $cred


 Version via $PSVersionTable.

PSVersion property on the $PSVersionTable automatic variable. This method will always represent the PowerShell engine.


 



















Wednesday, April 21, 2021

Extract IP address from text with regular expression and TextPad

I have a text file like the below, we want to extract the IP's from this :


[Service blocked: CP] from source 192.168.1.51, Wednesday, Apr 21,2021 04:19:16

[Service blocked: CP] from source 192.168.1.51, Wednesday, Apr 21,2021 04:19:03

[Service blocked: CP] from source 192.168.1.16, Wednesday, Apr 21,2021 04:18:52

[Service blocked: CP] from source 192.168.1.51, Wednesday, Apr 21,2021 04:18:40

[Service blocked: CP] from source 192.168.1.51, Wednesday, Apr 21,2021 04:18:12

[Service blocked: CP] from source 192.168.1.16, Wednesday, Apr 21,2021 04:17:47

[Service blocked: CP] from source 192.168.1.51, Wednesday, Apr 21,2021 04:17:39

[Service blocked: CP] from source 192.168.1.51, Wednesday, Apr 21,2021 04:17:00

[Service blocked: CP] from source 192.168.1.16, Wednesday, Apr 21,2021 04:16:42

[Service blocked: CP] from source 192.168.1.51, Wednesday, Apr 21,2021 04:16:38

[LAN access from remote] from 179.60.150.46:44350 to 192.168.1.15:5001, Wednesday, Apr 21,2021 04:16:27


To do this :


  • Ctrl+H
  • Find what: ^.+?((?:\d+\.){3}\d+).+$
  • Replace with: $1
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

 

View Example Here


Explanation:

^           : beginning of line
.+?         : 1 or more any character but newline
(           : start group 1
  (?:       : start non capture group
    \d+     : 1 or more digit
    \.      : a dot
  ){3}      : end group, must appear 3 times
  \d+       : 1 or more digit
)           : end group 1
.+          : 1 or more any character but newline
$           : end of line

Replacement:

$1          : content of group 1 (ie. the IP)

Result for given example:

54.246.81.158
175.36.129.24