U bekijkt momenteel de Netherlands versie van de site.
Wilt u overschakelen naar uw lokale site?
15 MIN LEESTIJD

LXF SHELL

Add some history to the LXF Shell

Refusing to ever learn from anything, Ferenc Deák realises that adding history to the LXF Shell will help him repeat his mistakes.

Part Six! Don’t miss next issue, subscribe on page 16!

OUR EXPERT

Ferenc Deák feels this project is his Sistine Chapel, only with less of the Pope shouting at him and more Mancunian editors.

The code for the shell still can be found at https://github. com/fritzone/lxf-shell.

In the world of the Linux shell, the command line history stands as a silent but powerful ally I to users navigating the intricate pathways of their systems. It serves as a virtual breadcrumb trail, providing users with a means to recall, analyse and replicate their past interactions with the system.

In this episode of our shell saga, we will delve into the mechanisms, practical applications and, last but not least, the implementation details of how to make the command line history work as expected by a grown-up shell. Not that ours is one, but it will be.

The mechanisms

Modern shells, such as Bash and Zsh, offer similar command history navigation using the up and down arrow keys, Ctrl+R for reverse search, and more advanced commands such as !n , !! and !string to execute specific or recent commands. For the implementation of this feature in our tiny shell, we plan to provide support for the previous and next elements. However, as it is not that difficult, we will also add some extra features: if the user presses Ctrl+Up/Down, we will search for the history in the current folder.

For the moment, we present the following structure for these hotkeys, without too much explanation – but no worries, that will come at a later stage: static const std::map> reservedKeys { {“Up”, {27, 91, 65}}, {“Down”, {27, 91, 66}}, {“CtrlUp”, {27, 91, 49, 59, 53, 65}}, {“CtrlDown”, {27, 91, 49, 59, 53, 66}},

};

Current shells usually keep the history in a file called .xxx_history, where xxx is based on the name of the shell, for example .bash_history. These are simple text files that contain all the commands executed since the shall was taken into first use. As our solution will be a bit more complex, we need a quick and dirty database set up for this, so a short intro to SQLite is to be found in the boxout (opposite). We will create the following database layout to store the commands. The following SQL script is used to create the database:

The structure of the database that’s running behind the scenes.

CREATE TABLE command ( id INTEGER PRIMARY KEY, command VARCHAR(255) );

CREATE TABLE location ( id INTEGER PRIMARY KEY, location VARCHAR(255) );

CREATE TABLE command_location ( created_at DATETIME, command_id INTEGER, location_id INTEGER, PRIMARY KEY (created_at), FOREIGN KEY (command_id) REFERENCES command (id), FOREIGN KEY (location_id) REFERENCES location (id) );

It might feel overcomplicated to have three tables, but we have to keep in mind, that:

A command can appear more than once;

Ontgrendel dit artikel en nog veel meer met
Je kunt genieten:
Geniet volledig van deze editie
Direct toegang tot 600+ titels
Duizenden oude edities
Geen contract of verplichting
ABONNEER NU
30 dagen proberen, dan gewoon €11,99 / maand. Op elk moment opzeggen. Alleen nieuwe abonnees.


Meer informatie
Pocketmags Plus
Pocketmags Plus

Dit artikel komt uit...


View Issues
Linux Format
November 2024
IN DE WINKEL BEKIJKEN

Andere artikelen in dit nummer


LINUX FORMAT
MEET THE TEAM
This issue, we’re setting up Qubes OS for total privacy. What little thing do you do to help bolster your privacy or security either on or offline?
LINUX FORMAT
The #1 open source mag Future Publishing Limited,
WELCOME
Reassuringly expensive
Linux Format has cost £6.49 for over
REGULARS AT A GLANCE
Linux summit points to Rust and RISC future
PLUMBERS CONFERENCE
Rust vs C out of control
The promise of memory-safe Rust code provokes ugly debates leading to police intervention.
Snapdragon support improving
ARM64 image of Ubuntu 24.10 to support X13s.
MANY TONGUES
Italo Vignoli is one of the founders
REDISCENT EVILS!
Dave Stokes is a technology evangelist at
Linux is finally a real-time OS!
The culmination of decades of hard work was realised in September.
Microsoft adopts SPIR-V
In a surprise move, Microsoft moves to the open format.
MS hands over Mono to Wine
Microsoft donates Mono to Wine, urging migration to modern .NET.
Distro Watch
What’s behind the free software sofa?
SMART AUDIO
Julian Bouzas is a senior software engineer
RT ARTISTS
Jon Masters is a kernel hacker who’s
Kernel Watch
Jon Masters summarises the latest happenings in the Linux kernel, so that you don’t have to.
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
LoRa, LoRa laughs As an LXF fan/reader, I’m
Helpdex
shane_collinge@yahoo.com
Snoop
THE BEST NEW OPEN SOURCE SOFTWARE ON THE PL ANET
Nuclear
MUSIC PLAYER
Media Downloader
Version: 5.0.1 Web: https://mhogomchungu . github.io/media-downloader/
Concessio
LEARN FILE PERMISSIONS
Endless Key
Version: 0.9 Web: www.endlessos.org/key
Tuta
EMAIL CLIENT
Fire Dragon
Version: 11.18.1-1 Web: https:// firedragon.garudalinux.org
AntiMicroX
JOYSTICK BUTTON MAPPER
LibreQuake
Version: 0.07-beta Web: https://librequake.queer.sh
NNN
FILE MANAGER
Micro
Version: 2.0.14 Web: https://microeditor.github.io/index.html
REVIEWS
Framework 13
Brandon Hill loves what this is doing for his eyes!
4MLinux 46.0
Nate Drake dives into this innovative, lightweight Polish distro to pose the burning question: are you 4M or against ’em?
Liya 2.0
Nate Drake takes a gander at this rolling Arch-based distro offering powerful performance and a slick interface. Shame about the updates.
PorteuX 1.6
Nate Drake delves into this Slack-based distro. Does it live up to its claims of being fast, small and portable?
RebeccaBlackOS 2024
Nate Drake is getting that Friday feeling as he discovers all that’s awesome about this celebrity-themed distro with Wayland support.
World of Goo 2
Recycling goo has The Management ecstatic at the chances it’ll give Kerry Brunskill to reuse all of their old work to increase profits.
ROUNDUP
Media servers
Without wishing to turn into a couch potato, Michael Reed examines five media servers that mean he could become one if he decided to.
Basic server install options
Hopefully, you’ve got a good array of options for setting up the server.
Initial setup process
Let’s get some folders set up, media shared and cover other basics.
Network access to content
Open standards over the network.
Access over the internet
For when you want to access your media wherever you are.
Support and documentation
Help to get it set up, make it work how you want and troubleshoot issues.
Official client app
The clients are front-ends that allow you to interact with your content.
Add-ons and extra features
Pushing systems beyond their basic media server functions.
Media servers
T he reason we chose Kodi as our winner
ALSO CONSIDER
Emby ( https://emby.media ) is a media
Build Your LINUX FORTRESS!
Chronically insecure and unreasonable Jonni Bidwell needs reasonable operational security. With Qubes, and containment and isolation, he finds a solution
The Qube-ic formula
What on earth is Qubes? How can it stop your traitorous activities being noted by hostile governments?
Stacking secure Qubes
Enough with the waffle, we hear you cry. Fine, let’s get this Qubes thing installed and set up.
Configure your Qubes
Find out where Qubes differs from other distros and join the single-use society with Disposable qubes.
Sending packets over Qubes tubes
Get Qubes working the way you want, find out how networking works, and start making your own qubes.
Free AI courses from Pi Foundation & Google
The hottest current topic can now be picked up by educators for free online.
Pi Rust
Embedded stability.
Pico VS Code
Easy coding time.
THE IMPRESSIVE POWER OF PI
Les Pounder works with groups such as
Recalbox 9.2
Les Pounder travels back to a time when a pocket full of change could open the door to whole new worlds.
Ultramarine Linux
Les Pounder knows that good looks will only get you so far, and Ultramarine Linux has the looks, but sadly none of the performance.
Work with Pi Pico temperature sensors
HEAT SENSORS
THE DHT11 AND DHT22
OK, one more sensor. The venerable DHT11, the
Power projects with the best Pi Pico LEDs
RGB LEDS
IN DEPTH
OPEN PROTOCOLS MATTER
Google and Amazon might be behind the latest IoT protocol, but Tam Hanna is just the guy to bring it to the masses, with a little help from Arduino…
TUTORIALS
Clean up filenames
You don’t have to get up at 4am and practise yoga to find balance in life. Shashank Sharma found inner peace by cleaning up filenames.
Secure the Linux system and its files
The ever-watchful Nick Peers discovers how Linux is built from the ground up to help keep you and your data secure.
IRC: the oldest chat system going on strong
Chatterbox Nate Drake walks you through how to set up and secure your very own IRC server, as well as master its many commands.
Radio astronomy – tune in to the aurora
Radio astronomy isn’t as difficult as you might think. Mike Bedford shows how to get going with just your PC audio system and some free software.
Upgrade it: Enhance your viewing pleasure!
It’s worth spending more on a good display, because you could be using it longer than any other component, says Neil Mohr.
Pixio PXC277 Advanced
The best budget 1440p display to grab right now.
Gigabyte M32UC
An “entry-level” 4K high-refresh gaming display.
Asus TUF Gaming VG289Q
The best choice for budget 4K gaming.
BenQ 23.8” MOBIUZ EX240N
1080p displays aren’t dead or buried yet!
Dell S3221QS
Best all-round choice if you fancy curves in your life.
BenQ SW321C PhotoVue
A 4K display targeting photo and video professionals.
Asus ROG Swift PG27AQDP
The best gaming OLED display – but at a price.
Dell UltraSharp UP3218K
For extreme 8K resolution and price, this is for you!
ADMINISTERIA
Simplify network configs with Tailscale
No one calls Stuart Burns a simple man, but he appreciates tools that simplify his admin life, especially for networking.
MAXIMISE YOUR SEED SPEEDS!
Nate Drake introduces you to one of the internet’s best kept secrets to turbocharge your downloads and uploads.
CODING ACADEMY
Using Osquery to explore your system
Ever-curious David Bolton shows how to use the Osquery application to view your system via a series of SQL select queries.
Chat
X
Pocketmags ondersteuning