Product
Coming from bash and PowerShell
A line written in the habits of bash or PowerShell is read and, where the target is safe, translated to a Nurt program.
What the console does with a habit
A line that starts with a bash command is read with the rules of the POSIX shell, and a line that starts with a cmdlet of the form Verb-Noun is read as PowerShell. A line is read as a bash command when it shows notation that only the shell has, such as a flag, an operator or $NAME. The console translates the line to a Nurt program and shows both corrected and ran, the program that was executed (bash migration, PowerShell migration).
A translation that rests on an assumption and touches the target of a change waits for the choice of the caller. The answer is E_AMBIGUOUS with ready programs, and a call with accept runs the candidate that the caller chooses. A flag without a counterpart is answered with an error that lists the parameters of the command. The cheat sheets give the result of every habit: corrected automatically, or an error that carries the fix.
What is the same
- Familiar command names are kept as synonyms:
cat,psandwhichare read by their bash meaning when the arguments are those of bash. - A pipe
A | BbecomesA |> Bwhen both sides translate, andWhere-Object,Sort-ObjectandSelect-Object -Firstmap tofilter,sortandfirst. - Conditions, loops, functions and script parameters of bash are translated since 0.1.1:
if,elif,else,caseand the tests[ ],[[ ]]andtestbecomewhen;for,whileanduntilbecomeeach,whileandrepeat until; functions becomedefine;$1,$2,$@,shiftandgetoptsbecome aparamsblock. sudo,doasandrun0are translated into the call parameterprivilege: elevated, andsudo -u NAMEintoas_user.- An existing script keeps running:
run ["bash", "script.sh"] cwd: "/srv/app"starts it unchanged, andnurt migratetranslates a script to a Nurt program. -WhatIfof PowerShell becomes the call parameterpreview: true.- The administration programs
useradd,usermod,userdel,groupadd,mount,sysctl -w,modprobe,ufw,firewall-cmd,nft,iptables,ip route,timedatectl,shutdown,partedandmkfs.*are translated into the native commands of the groupadministrationsince 0.1.1.
What differs
- Absolute paths. A path is absolute and quoted, with
/as the separator on every system, and a relative path takes the call parameterbase.cd D && CMDis translated, for an absolute path in the same line, as thecwdofrun; a program that works in a directory names it incwd. - Records instead of text. A stage returns records with named fields, so
ps auxbecomesprocessesand the later stages filter on fields. - One changing effect per pipeline. A pipeline with two changing stages joined by
&∨is answered with the errorE_ONE_EFFECT, which offers the same changes insidesteps { … }as the first candidate. Astepsblock is one journal entry, all or nothing. - Elevation as a parameter. Elevation is the parameter
privilege: elevatedon the command that needs it;sudo -iandsuare answered withE_AMBIGUOUS, because an elevated session is not a command. The console never asks for a password. - Recursion is the default.
rm -rfandcp -rneed no counterpart of-r, and a missing path is skipped. - Undo. A change to files is recorded in the journal and can be reviewed and reverted with
historyandundo; effects outside the file system are recorded as irreversible, unless the command has an inverse operation.
Paired commands
The pairs are rows of the cheat sheets. The paths are those of the host named in each sheet; every row is corrected automatically.
| Habit | Nurt |
|---|---|
rm -rf /home/user/app/build |
remove "/home/user/app/build" |
mkdir -p /home/user/app/out |
create "/home/user/app/out" type: directory |
tail -n 20 /home/user/app/a.log |
read "/home/user/app/a.log" last: 20 |
sed -n '10,20p' /home/user/app/a.go |
read "/home/user/app/a.go" lines: 10..20 |
ps aux |
processes |
systemctl restart nginx |
services name: "nginx" |> restart |
sudo systemctl restart nginx |
services name: "nginx" |> restart privilege: elevated |
git -C /home/user/app status |
git.status "/home/user/app" |
Get-ChildItem C:\Users\user\app -Recurse -Filter *.go |
find "C:/Users/user/app" glob: "**/*.go" type: any hidden: false |
Get-Content C:\Users\user\a.log -Tail 20 |
read "C:/Users/user/a.log" last: 20 |
Get-Process | Sort-Object WorkingSet -Descending |
processes |> sort memory order: desc |
Restart-Service nginx |
services name: "nginx" |> restart |
A habit that has a safe form is written once and then repeated in the Nurt form:
find "/srv/app" glob: "**/*.tmp" |> remove
The console lists the targets it computed before the removal, and the journal keeps the removed files, so an undo restores them.
A list of changing commands becomes one block with one journal entry (bash migration guide):
mkdir -p /srv/out && cp -a /srv/in/data.csv /srv/out/
steps {
create "/srv/out" type: directory
copy "/srv/in/data.csv" into: "/srv/out"
}
A program that runs in the background is written with background: true:
run ["npm", "run", "build"] cwd: "/home/user/app" background: true
The platform sides
On Linux and macOS, attributes, services and package.install take the place of chmod, systemctl and the package managers, and the case rules of file names follow the system (Unix guide). On Windows, the registry is addressed as a path with the prefix registry:, windows.cim replaces Get-CimInstance and Invoke-CimMethod, and files in code pages such as 852 or 1250 are read with encoding (Windows guide). The registry provider belongs to Windows.
Where to go next
Cheat sheet: bash
Every row pairs a bash command with its form in Nurt.
Cheat sheet: PowerShell
Every row pairs a PowerShell command with its form in Nurt.
Guide: bash migration
What is corrected, and how scripts are handled.
Guide: PowerShell migration
The cmdlets that are translated and their parameters.
The use cases page shows complete programs for editing, Git and administration.