55 lines
2.2 KiB
Markdown
55 lines
2.2 KiB
Markdown
# Linux - How to work with complex commands
|
|
|
|
It can frustrate to work on complex commands in the terminal. I'll present you some tips on how to manage them. If you have another tip, I'd appreciate a quick message.
|
|
|
|
### Use backslash`\` to add a line break
|
|
|
|
This is fairly simple. Having one or multiple long lines with no structure can be messy and confusing. By adding `\` for a line break adds more structure. A really simple example:
|
|
|
|
`podman run -d --restart=always -p 127.0.0.1:3001:3001 -v /path/data:/app/data --name status.brrl.net docker.io/louislam/uptime-kuma:latest`
|
|
|
|
With line breaks:
|
|
|
|
```markdown
|
|
podman run -d \
|
|
--restart=always \
|
|
-p 127.0.0.1:3001:3001 \
|
|
-v /path/data:/app/data \
|
|
--name status.brrl.net \
|
|
docker.io/louislam/uptime-kuma:latest
|
|
```
|
|
|
|
It is easier to read and work with, at least in my opinion.
|
|
|
|
### Work on complex commands in your favorite $EDITOR
|
|
|
|
I'lll show you now, how you can edit complex commands in your favorite CLI editor.
|
|
|
|
Enter command `fc`, or keep `CTRL` pressed and enter `x` and `e` as keyboard shortcut. This will open your default CLI editor. After finishing working on the command you want to run, simply 'save and close', and the command will run right after.
|
|
*I am going to show you how yo set your default editor at the end of the post.*
|
|
|
|
The `fc` command is normally used to show the command history or re-edit already entered commands, but we can use it to work on complex commands. `fc --help` to find out more.
|
|
|
|
### Set default editor in the CLI
|
|
|
|
There are various ways to set the default editors, so you might have to look it up for your setup.
|
|
|
|
In general, it works to set the `$EDITOR` environment variable with the editor of choice. On most distros it should be 'nano', but you might prefer something else.
|
|
|
|
If we want to change our default editor to 'vim' temporarily, we can enter this command:
|
|
|
|
`export EDITOR="/bin/vim"`
|
|
|
|
You can double-check with:
|
|
|
|
`echo $EDITOR` or `env | grep EDITOR`
|
|
|
|
and
|
|
|
|
`$EDITOR test.txt`
|
|
|
|
**Important:** To change the default editor permanently, add `export EDITOR="/bin/vim"` to your `.bashrc` or whatever config file you use.
|
|
|
|
From now on, whenever you want to edit a command with `fc`, your favorite editor will open.
|
|
|
|
---
|