Developer Blog

Tipps und Tricks für Entwickler und IT-Interessierte

Rust | Modern Alternatives of Command-Line Tools

Continue Reading

https://github.com/TaKO8Ki/awesome-alternatives-in-rust

Tools

bat

bat is a cat clone with syntax highlighting and Git integration that works on Windows, MacOS and Linux. It provides syntax highlighting for many file extensions by default.

exa

exa is a modern replacement for ls, the default command-line program in Unix/Linux for listing directory contents. exa supports icons with the --icons flag.

just

A command runner and partial replacement for make

Just create a justfile with the desired commands and your set.

When running with PowerShell, add the following at the start of your justfile:

set windows-shell := ["pwsh.exe", "-NoLogo", "-NoProfile", "-Command"]

fd

fd is a fast and user-friendly alternative to find, the built-in command-line program in Unix/Linux for walking a file hierarchy. fd provides opinionated defaults for the most common use cases. To find a specific file by name, you write fd PATTERN instead of find -iname ‘*PATTERN*’fd is also extremely fast and it comes with a ton of options like ignoring hidden directories, files and patterns from .gitignore by default.

procs

procs is a modern replacement for ps, the default command-line program in Unix/Linux for getting information about processes. It provides convenient, human-readable (and colored) output format by default.

sd

sd is an intuitive find & replace command-line tool, it is an alternative to sed, the built-in command-line program in Unix/Linux for parsing and transforming text (). sd has simpler syntax for replacing all occurrences and it uses the convenient regex syntax that you already know from JavaScript and Python. sd is also 2x-11x faster than sed.

sed is a programmable text editor, with search and replace being a common use case. In that light, sd is more like tr, but on steroids. (thanks /u/oleid for the suggestion).

dust

dust is a more intuitive version of du, the built-in command-line program in Unix/Linux for displaying disk usage statistics. By default dust sorts the directories by size.

startship

The minimal, blazing-fast, and infinitely customizable prompt for any shell.

ripgrep

ripgrep is an extremely fast alternative to grep, the built-in command-line program in Unix/Linux for searching files by pattern. ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern. By default, ripgrep respects .gitignore and automatically skips hidden files, directories and binary files.

rip

rip is an improved version of the rm command. It is faster, safer, and user-friendly. rip sends deleted files to a temp location so they can be recovered using rip -u. I really like the simplicity and the revert feature, as I don’t have to worry about accidentally deleting something using rm. While rip can be aliased to replace rm, the creators advise not doing that as you might get used to it and do rm on other systems where you cannot revert the delete.

toeki

tokei is a program that displays statistics about your code. It shows the number of files, total lines within those files and code, comments, and blanks grouped by language.

hyperfine

hyperfine is a command-line benchmarking tool. Among many features, it provides statistical analysis across multiple runs, support for arbitrary shell commands, constant feedback about the benchmark progress and current estimates and more.

ytop

ytop is an alternative to top, the built-in command-line program in Unix/Linux for displaying information about processes.

tealdeer

tealdeer is a very fast implementation of tldr, a command-line program for displaying simplified, example based and community-driven man pages.

bandwhich

bandwhich is a CLI utility for displaying current network utilization by process, connection and remote IP or hostname.

grex

grex is a command-line tool and library for generating regular expressions from user-provided test cases.

rmesg

rmesg is a dmesg implementation in Rust (and available as a library for Rust programs to consume kernel message logs.)

zoxide

zoxide is a blazing fast autojumper, intended to completely replace the cd command. It allows you to change directories without typing out the entire path name.

delta

delta is a viewer for git and diff output. It allows you to make extensive changes to the layout and styling of diffs, as well as allowing you to stay arbitrarily close to the default git/diff output.

tp-note

Tp-Note is a template tool that enhances the clipboard with a save and edit as a note file function. After creating a new note file, Tp-Note launches the user’s favorite file editor (for editing) and web browser (for viewing).

nushell

nushell is a new type of shell, written in Rust. Its goal is to create a modern shell alternative that’s still based on the Unix philosophy but adapted to the current era. It supports piping and filtering in a way similar to awk and sed with a column view so that you can combine operations like in SQL. (thanks /u/matu3ba for the suggestion).

xcp

xcp is a partial clone of the cp command. It is faster and more user-friendly with progress bars, parallel copying, .gitignore support, and so on. I like its simplicity and developer experience, especially the progress bars. I have aliased cp to xcp so I can use it everywhere.

zoxide

zoxide is a smarter cd replacement. It remembers the directories you visit, and you can jump to them without providing a full path. You can provide partial paths or even a word from the path. When there are similar paths, zoxide offers an interactive selection using fzf. It is super fast and works with all major shells. I like how it works, and I have aliased cd to z so I can use it everywhere.

atuin

Magical shell history

bottom

Yet another cross-platform graphical process/system monitor.

broot

A new way to see and navigate directory trees.

choose

A human-friendly and fast alternative to cut and (sometimes) awk.

counts

A tool for ad hoc profiling.

delta

A syntax-highlighting pager for git, diff, and grep output.

difftastic

A syntax-aware diff.

dog

A command-line DNS client.

dua

View disk space usage and delete unwanted data, fast.

eza

A modern version of ls.

fclones

Efficient duplicate file finder.

felix

TUI file manager with vim-like key mapping.

ffsend

Easily and securely share files from the command line (Firefox Send client).

frum

A modern Ruby version manager written in Rust.

fselect

Find files with SQL-like queries.

git-cliff

Highly customizable changelog generator.

gptman

A GPT manager that allows you to copy partitions from one disk to another and more.

himalaya

Command-line interface for email management.

htmlq

Like jq, but for HTML. Uses CSS selectors to extract bits of content from HTML files.

inlyne

GPU powered terminal markdown viewer.

jless

Command-line JSON viewer for exploring and searching JSON.

jql

A JSON query language CLI tool.

legdur

Compute hashes of large sets of files and compare with snapshots.

lemmeknow

Identify or analyze mysterious text and hard-coded strings.

lfs

A Linux utility to get information on filesystems; like df but better.

lsd

Next generation ls command.

macchina

Fast, minimal, and customizable system information frontend.

mdBook

Create books from markdown files (like GitBook).

mdcat

Fancy cat for Markdown.

miniserve

Serve files and directories over HTTP (replacement for Python’s SimpleHTTPServer).

monolith

Save complete web pages as a single HTML file.

ouch

Painless compression and decompression for your terminal.

pastel

Generate, analyze, convert, and manipulate colors on the command line.

pipr

A tool to interactively write shell pipelines.

qsv

CSVs sliced, diced & analyzed (fork of xsv).

rargs

xargs plus awk with pattern matching.

ripsecrets

Find secret keys in your code before committing them to git.

rnr

Command-line tool to batch rename files and directories.

skim

Command-line fuzzy finder.

teehee

Modal terminal hex editor.

tin-summer

Find build artifacts that are taking up disk space.

topgrade

Upgrade all of your tools.

watchexec

Execute commands in response to file modifications.

xh

Friendly and fast tool for sending HTTP requests.

xsv

Fast CSV command line toolkit (last updated in 2018).


Rust | Cookbook

Fehler und deren Behebung

Problem

cargo build
error: no default toolchain configured

Lösung

Ermitteln, welche Toolchains installiert sind

rustup toolchain list

Toolchain installieren

rustup install stable
rustup default  stable

Rust | Getting Started

Introduction

From Wikipedia, the free encyclopedia:

Rust is a multi-paradigm programming language focused on performance and safety, especially safe concurrency. Rust is syntactically similar to C++, and provides memory safety without using garbage collection.

Rust was originally designed by Graydon Hoare at Mozilla Research.

It has gained increasing use in industry and is now Microsoft’s language of choice for secure and safety-critical software components.

Rust has been the “most loved programming language” in the Stack Overflow Developer Survey every year since 2016.

Rust could be used in different areas

Read more

Installation

Rustup

Download install script and run it

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Modify .bashrc to add Rust path to PATH

source $HOME/.cargo/env

Other way to install Rust on MacOS

brew install rust

Create and run your first App

Create the app

$ cargo new hello_world
$ cd hello_world

Show folder structure

$ tree .
.
├── Cargo.lock
├── Cargo.toml
└── src
    └── main.rs
1 directory, 3 files

Show main source file

fn main() {
    println!("Hello, world!");
}

Build your app

$ cargo build
Compiling hello_world v0.1.0 (.../hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 6.32s

Or build a production ready version

$ cargo build --release<br>Finished release [optimized] target(s) in 0.19s

Run your app

$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/hello_world
Hello, world!

Add functionality to your app

Add Dependencies

Let’s add a dependency to our application. You can find all sorts of libraries on crates.io, the package registry for Rust. In Rust, we often refer to packages as “crates.”

In this project, we’ll use a crate called ferris-says.

In our Cargo.toml file we’ll add this information (that we got from the crate page):

[dependencies]
ferris-says = "0.1"

Modify main source

Now let’s write a small application with our new dependency. In our main.rs, add the following code:

use ferris_says::say; // from the previous step
use std::io::{stdout, BufWriter};

fn main() {
    let stdout = stdout();
    let message = String::from("Hello fellow Rustaceans!");
    let width = message.chars().count();

    let mut writer = BufWriter::new(stdout.lock());
    say(message.as_bytes(), width, &mut writer).unwrap();
}

Run App

$ cargo build
    Updating crates.io index
  Downloaded object v0.20.0
  Downloaded textwrap v0.11.0
  Downloaded adler v0.2.3
  Downloaded ansi_term v0.11.0
  Downloaded miniz_oxide v0.4.1
  Downloaded gimli v0.22.0
  Downloaded strsim v0.8.0
  Downloaded error-chain v0.10.0
  Downloaded vec_map v0.8.2
  Downloaded clap v2.33.3
  Downloaded smallvec v0.4.5
  Downloaded ferris-says v0.1.2
  Downloaded backtrace v0.3.50
  Downloaded rustc-demangle v0.1.16
  Downloaded addr2line v0.13.0
  Downloaded 15 crates (1.4 MB) in 1.65s
   Compiling libc v0.2.76
   Compiling bitflags v1.2.1
   Compiling gimli v0.22.0
   Compiling adler v0.2.3
   Compiling rustc-demangle v0.1.16
   Compiling unicode-width v0.1.8
   Compiling object v0.20.0
   Compiling cfg-if v0.1.10
   Compiling strsim v0.8.0
   Compiling vec_map v0.8.2
   Compiling ansi_term v0.11.0
   Compiling smallvec v0.4.5
   Compiling textwrap v0.11.0
   Compiling miniz_oxide v0.4.1
   Compiling addr2line v0.13.0
   Compiling atty v0.2.14
   Compiling backtrace v0.3.50
   Compiling clap v2.33.3
   Compiling error-chain v0.10.0
   Compiling ferris-says v0.1.2
   Compiling hello_world v0.1.0 (.../hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 14.73s

Run your app

$ cargo run
     Finished dev [unoptimized + debuginfo] target(s) in 0.14s
       Running`target/debug/hello_world`
----------------------------
| Hello fellow Rustaceans! |
----------------------------
              \
               \
                  _~^~^~_
              \) /  o o  \ (/
                '_   -   _'
                / '-----' \

Next steps

Read Getting Started on rust homepage

Explore Learn Rust

Next Readings

Readings

Exercises