Ravas coding goodies

For discussions about programming and projects not necessarily associated with Porteus.
User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 3924
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

Ravas coding goodies

Post#46 by ncmprhnsbl » 03 Oct 2021, 13:28

Rava wrote:
03 Oct 2021, 11:15
Is it really part of any flavour of Port 5.0rc3?
not really, it was offered as bundle for openbox for RC1 (now archived) eg. http://mirrors.dotsrc.org/porteus/x86_6 ... 1/bundles/
it would seem it still works for RC3
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#47 by Rava » 03 Oct 2021, 20:31

ncmprhnsbl wrote:
03 Oct 2021, 13:28
it would seem it still works for RC3
Just shows how good Porteus really is. :celebrate3:
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#48 by Rava » 04 Oct 2021, 20:31

The discussion about what we talked about started a few posts above, but the main issue of using file type vs file extension in determining syntax highlighting was ncmprhnsbl post here: btop (Post by ncmprhnsbl #84588)
ncmprhnsbl wrote:
04 Oct 2021, 01:45
text editors should (auto)set syntax highlighting based on content, not file extension..
I presumed geany would not go down the dark and dirty path Mousepad uses. testing it it seems my presumption was correct.

I copied a script to /tmp, changed it from ownership root.root to guest.users:

Code: Select all

root@porteus:/tmp# stat /usr/local/bin/ffplay-hide_banner-drawtext /tmp/ffplay-hide_banner-drawtext*|grep -E "File:|Access: \("
  File: /usr/local/bin/ffplay-hide_banner-drawtext
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
  File: /tmp/ffplay-hide_banner-drawtext
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/   guest)   Gid: (  100/   users)
  File: /tmp/ffplay-hide_banner-drawtext.sh
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/   guest)   Gid: (  100/   users)
Then I opened both /tmp/ffplay-hide_banner-drawtext* in geany and checked the syntax highlighting of /tmp/ffplay-hide_banner-drawtext :
Image

and then did the same with

Code: Select all

guest@porteus:/tmp$ mousepad ffplay-hide_banner-drawtext*
again only checking the script without .sh extension:
Image

As you can see, geany wins this race with flying colours, while Mousepad fails.
I not updated geany in ages, since it still runs flawlessly in even the newest of Porteus 5.0rc version, so the only program that got updated by default is Mousepad. :)
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#49 by Rava » 04 Oct 2021, 20:39

I expanded the capabilities of my previous mentioned make-ffplay-script script.

It now determines between media files containing video and ones that only have sound.
I have not tested that with many available media file. Please report any errors so I can hopefully find a workaround.

The idea is: when a media file is sound only, I want the default visualisation be "waves" instead of the default "RDFT ((Inverse) Real Discrete Fourier Transform)" and adjust the resulting window in having reduced height, or more precise: use -x 500 -y 150 . The default window size is okay for a video file to be played, but sheer overkill when the file is a mere sound file.

To not clutter the resulting play-mediafile.sh with code, I use a script named

Code: Select all

ffplay-hide_banner
instead. That script needs to be executable and in the user's $PATH.

Here it is:

Code: Select all

#!/bin/sh
VERSION="0.2"
MYNAME="ffplay-hide_banner"

echo -e "$MYNAME V$VERSION"

ffprobe -hide_banner 2>&1 "$*" |grep Stream|grep "Video:" >/dev/null
if [ $? -eq 0 ]; then
	# return-value zero -> video: default
	ffplay -autoexit -hide_banner -i "$*"
else
	# return-value non-zero -> audio only - adjusting…
	ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i "$*"
fi
Be aware that ffplay-hide_banner by default suppresses error messages of the started ffprobe . If something is off or seems to be malfunctioning for you, temporarily remove the >/dev/null at the end of this line

Code: Select all

ffprobe -hide_banner 2>&1 "$*" |grep Stream|grep "Video:" >/dev/null
but be aware that the output will get very much more verbose. Even more so when you change the above line from the whole script into these:

Code: Select all

#for debugging purposes only!
echo "______________________________________
"
ffprobe -hide_banner 2>&1 "$*"
echo "______________________________________"
ffprobe -hide_banner 2>&1 "$*" |grep Stream|grep "Video:" >/dev/null
And this is the new make-ffplay-script

Code: Select all

#!/bin/sh
MYVERSION=V3.45# please add V at the beginning!
# V3.4 - $1 is the relative folder with the files, will be stripped of any "/" - e.g. Filme or Filme/ works but not /mnt/sda1/video/Filme nor /mnt/sda1/video/Filme/
# for now supported file endings are
# avi 	flv	mp3	mp4	mpg	mkv	ogv	TS	ts	webm	divx 	VOB	vob
# V3.4: now added "chmod -v a+x "$PARAMETER".sh - will create error message on NTFS or VFAT fs, necessary for Linux fs like ext2,ext3 etcetera.
# V3.5: now uses ffplay-hide_banner script instead of calling ffplay itself. ffplay-hide_banner distinguishes between video and media-file that is sound only. In the latter case the following is added: -showmode waves -x 500 -y 150 
echo make-ffplay-script $MYVERSION
PARAMETER=$(echo "$1"|sed 's|/||g')
if [ -d "$PARAMETER" ]; then
	echo working on "$PARAMETER"… writing into "$PARAMETER".sh
	echo '#!/bin/sh
echo "$0"' >"$PARAMETER".sh
	find "$PARAMETER" |grep -E "\.avi$|\.flv$|\.mp[34g]$|\.mkv$|\.ogv$|\.[tT][sS]$|\.webm$|\.divx$|\.[vV][oO][bB]$" |sort | while read line ; do
{
 echo ffplay-hide_banner \"${line}\" >>"$PARAMETER".sh
} ; done
	chmod -v a+x "$PARAMETER".sh
else
	echo Given parameter "$PARAMETER" is not a directory. Abort.
	exit 1
fi
Be aware if the resulting script is on a VFAT or NTFS filesystem you get an error similar to this one while executing make-ffplay-script:

Code: Select all

chmod: changing permissions of 'Scissor Seven.sh': Operation not permitted
failed to change mode of 'Scissor Seven.sh' from 0777 (rwxrwxrwx) to 0777 (rwxrwxrwx)
Oh boo hoo, not able to change mode from 0777 to 0777. What a disaster. </irony>
____________________________________________

When you use your DE-filebrowser (e.g. DE:XFCE; filebrowser:Thunar) to use ffplay-hide_banner to open media files, it then also enables your DE to alter the resulting audio-only window.

And just in case you also need a ffplay-version that loops the file and also distinguishes between video and audio-only like ffplay-hide_banner above: here it is. I call it ffplay-hide_banner-loop

Code: Select all

#!/bin/sh
VERSION="0.2"
MYNAME="ffplay-hide_banner-loop"

echo -e "$MYNAME V$VERSION"

ffprobe -hide_banner 2>&1 "$*" |grep Stream|grep "Video:" >/dev/null
if [ $? -eq 0 ]; then
	# return value zero -> video : default
	ffplay -autoexit -hide_banner -loop 0 -i "$*"
else
	# return value non-zero -> audio only - adjusting…
	ffplay -autoexit -hide_banner -loop 0 -showmode waves -x 500 -y 150 -i "$*"
fi
# V0.2	using ffprobe to determining if file is sound only, then alter the window appearance and visualisation
Last edited by Rava on 09 Nov 2021, 02:42, edited 1 time in total.
Reason: added possible debug code
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Ravas coding goodies

Post#50 by Ed_P » 05 Oct 2021, 04:56

You're very skilled with scripting Rava. It could be helpful if you could look at USM and tweak it's code to update without errors and to run on 5.0rc3. :)
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#51 by Rava » 05 Oct 2021, 05:22

Ed_P wrote:
05 Oct 2021, 04:56
You're very skilled with scripting Rava.
Thanks, you are welcome, but others on here are at least as talented as I am.
Ed_P wrote:
05 Oct 2021, 04:56
It could be helpful if you could look at USM and tweak it's code to update without errors and to run on 5.0rc3. :)
RL does not give me the time. USM is a huge project that does a lot. When there are other volunteers (at least 2 more besides me) to share the workload, I could help. But by myself? Nope.

Just look into USM yourself and you see what I mean.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Ravas coding goodies

Post#52 by Ed_P » 05 Oct 2021, 05:29

Rava wrote:
05 Oct 2021, 05:22
Just look into USM yourself and you see what I mean.
Oh I have and it is WAY over my head. :(
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#53 by Rava » 05 Oct 2021, 18:20

Since an image shows more than a thousand words, or so they say, I made two screenshots.
The first shows my original ffplay-hide_banner version, actually just doing what it names says: executing ffplay and -hide_banner:
All files are opened via

Code: Select all

ffplay -autoexit -hide_banner -i "$*"
I cropped both 1920x1080 screenshots to 632,295 : 658 x 513 (original X,Y : new_width x new_height)

Image

And here is what ffplay-hide_banner version 0.2 makes out of it, determining via ffprobe that the multi-media-file is sound only, and therefore opening it via :

Code: Select all

ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i "$*"
Image

Added in 1 day 3 hours 26 minutes 45 seconds:
By using ffplay-hide_banner v0.2 you can even determine via a ps|grep which running ffplay is sound only and which has video:

Code: Select all

root@porteus:~# type psg
psg is a function
psg () 
{ 
    /bin/ps ax | /bin/grep $* | /bin/grep -v grep
}

root@porteus:~# psg ffplay-hide_banner
 1526 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner /sound/Clannad Original Soundtrack (Full Album)-J-0twocIam4.webm
 9275 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner /video/Filme/Love, Chunibyo & Other Delusions the Movie - Rikka Takanashi Revision.mp4
 9330 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner-loop /sound/WhiteNoise - 10 Hours.aac
31158 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner /sound/VIOLET EVERGARDEN: Echo Through Eternity non singing+2.webm

psg ffplay-hide_banner itself hides the details, but psg ffplay|grep -v ffplay-hide_banner shows them:

Code: Select all

root@porteus:~# psg ffplay|grep -v ffplay-hide_banner
 1532 tty2     SLl   17:09 ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i /sound/Clannad Original Soundtrack (Full Album)
 9288 tty2     SLl    0:05 ffplay -autoexit -hide_banner -i /video/Filme/Love, Chunibyo & Other Delusions the Movie - Rikka Takanashi Rev
 9336 tty2     SLl    0:05 ffplay -autoexit -hide_banner -loop 0 -showmode waves -x 500 -y 150 -i /sound/WhiteNoise/Hairdryer White Noise
31164 tty2     SLl   29:21 ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i /sound/VIOLET EVERGARDEN: Echo Through Eternity non sing
Nice to see which are sound-only: PID 1532+9336+31164
Sound and video in this example is PID 9288

You can even determine if ffplay-hide_banner was executed via file browser or from a terminal, or via script as created by make-ffplay-script V3.45 or higher: because then it uses relative paths like here:

Code: Select all

root@porteus:~# psg ffplay|grep -v ffplay-hide_banner|grep Narayan,Ram
 9507 pts/7    SLl+   0:05 ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i Narayan,Ram/Masters of Raga/01 Rag Marwa- Alap.mp3
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#54 by Rava » 10 Oct 2021, 20:30

You can set up a custom action in your file browser that lets you create the make-ffplay-script without the need of a terminal:

This is how it works in XFCE/Thunar:
Main menu ▷ Edit ▷ Configure custom action

▷ Create a new custom action.

If your make-ffplay-script sits in /usr/local/bin the main tab looks like this:
Image

and the 2nd tab like this:
Image

Cave! The script only accepts exactly one folder as parameter. If you give it more than one it would print an error message (which you not see, since no terminal got opened) and nothing would be created.
So, select only one folder.

This is how it looks like in the context menu (aka right-mouse-click menu) when you select a folder and open the context menu:
Image
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#55 by Rava » 18 Oct 2021, 02:05

Code: Select all

<!doctype html public "-//w3c//dtd html 4.1 strict//en">
	<!-- V 0.47 2021-09-25 mailto: linux at ***CENSORED*** -->
	<html lang="de"><head>
	<link rel="icon" type="image/png" href="data:image/png;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAQABADASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAACAUH/8QAFQEBAQAAAAAAAAAAAAAAAAAAAgj/2gAMAwEAAhADEAAAARduSylS4f/EABkQAAMBAQEAAAAAAAAAAAAAAAQFBgMBB//aAAgBAQABBQIBAxoC9fCj+DTIYCGavqPOYRf/xAAdEQACAwACAwAAAAAAAAAAAAABAgMEEQUSEyEi/9oACAEDAQE/AbXNWrdySGlGFiHxFqBpJZCxXye9CxLnYnAFXSzEjqP/xAAbEQACAgMBAAAAAAAAAAAAAAADBAEFAgYHE//aAAgBAgEBPwHZu89D2nfFNZ51iKori3DNQh6Vitla3kqmIs1Y5Q3gwJKrFITsyzABjUWXMRk5zRKmP//EACAQAAICAgIDAQEAAAAAAAAAAAIDAQQFEQASEyEiFDP/2gAIAQEABj8CKli6/ncKmPZsgWtaVxsjYw5EBjcwI7nZHIiO5nibVnP0EwRDDwXUsOMdjM9a32v9Ld+hCYRE+ykxiOYpaK4NyeXr17LRSIFdteaBsHsuw9ay/wCXdprrq+exQRe3OtPAs5ka7a+IorlxJqCcgt7Vs+JI1KKfLbOVsaUitIKWRDz/xAAXEAEBAQEAAAAAAAAAAAAAAAABEQBB/9oACAEBAAE/IeIHZuixGgKGaxMyiSVZpdDJtqqUAY0apOGDaKsNYpwURrWW/9oADAMBAAIAAwAAABDr/8QAFhEBAQEAAAAAAAAAAAAAAAAAAREA/9oACAEDAQE/EDoKzLgggAWwKY//xAAVEQEBAAAAAAAAAAAAAAAAAAAAAf/aAAgBAgEBPxCHzSZlQ3dPMn//xAAXEAEBAQEAAAAAAAAAAAAAAAABEQAQ/9oACAEBAAE/ECQLoRCvKhLiAJuwhoeQUXCbSnJiNZMPWF5ttzXL0UiEhwP/2Q=="/>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link rel="stylesheet" type="text/css" href="file:///E:/mb.css">
<title>Dr. Copy & Mr. Paste - Textfeld V0.47 2021-09-25 - f&uuml;r FullHD</title>
</head><body>
<form action="dummy.html">
<p>
<textarea name="dummy" cols="91" rows="20" style="border : dotted 2px black;"></textarea>
</p>
</form>
</body>
</html>
Why do I code myself an empty edit area that obviously has no function? ( form action= is an invalid target)

To be able to pre-write text using the installed dictionaries (EN-UK and DE-Alte-Rechtschreibung 1903) without the need to install similar dictionaries in Libre Office… or even the need to activate and run any huge office program when the browser is already running and all I want is a plain .txt (for a later-to-be posted forum article, or a later-to-be-sent email)

Yes, me is weird as that. :P Also, at times I am on a machine without permanent Internet access. :D
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#56 by Rava » 19 Oct 2021, 17:58

You are in a softlinked directory and want to go to the real one?

Last time that happened to me I was using my 4th defined "Places" in Thunar, aka what's in ~/.config/gtk-3.0/bookmarks.
Since I do think creating a long list of "Places" would make it confusing and unclear, I decided to just keep my main 3 "Places" - ebook - sound - video - and create a new Folder named LINKS that itself holds the symlinks all other folders that I need frequently.
Like my main Porteus_modules/5.0/ folder, or my debug/5.0_/ one…

I changed into the symlink of my /what/ever/debug/5.0_/ folder to compare file sizes of a screenshot I just made - png, webp & jpeg - to only keep the one with the smallest file size… realizing only two were in there when I expected three…

Opening mtpaint and looking into its recently opened or saved files listing in the File menu… I realized I saved the 3rd file in ".." by mistake, aka in /what/ever/debug/ instead of /what/ever/debug/5.0_/

But you can not simply change into ".." when you are in a symlinked folder, that would bring me only back to where the symlink itself sits: the LINKS folder in my case.

Opening a console and typing

Code: Select all

cd $(realpath .)
does the trick. I ponder if I should create a custom action for thunar "open recent folder's realpath in a new tab" or such.
But I think that most probably the occurrence of needing exactly that is so rare that I can again just "open terminal here" and then "cd $(realpath .)" and do what I want to do via console.

In the above example, "mv whatever.jpg 5.0_"

First I listed the most recent 26 files via lcrt since after typing this post I forgot the exact file name in the meantime.

Code: Select all

$ type lcrt
lcrt is a function
lcrt () 
{ 
    /bin/ls -oatr --time-style=long-iso "$@" | tail -n 26 | cut -c 14-93
}
Cave! The function is stupid like many of my similar aliases or functions are: they just presume $COLUMNS being 80 and calculate based on that. On my system that is usually the case so they all work okay as intended for me.
But when you have a different $COLUMNS "cut -c 14-93" might be a wrong preset for you.
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#57 by Rava » 25 Oct 2021, 07:18

I not recall if I mentioned my "help.*" scripts here or not.
Basically the * part is either a program name or an issue/matter name. My current help.* scripts are these (shown via double-pressing [TAB] key in terminal to show what help.* executables there are)

Code: Select all

help.7z                            help.mmv
help.COLUMNS+LINES                 help.mount
help.EMPTY                         help.mplayer
help.TZ                            help.mtpaint
help.appimage                      help.nero
help.aria2c                        help.notify-send
help.cdda2wav                      help.opera
help.cdparanoia                    help.perl
help.cdrdao                        help.qiv
help.cdrecord                      help.realpath
help.cp                            help.recordmydesktop
help.ctorrent                      help.regex
help.date+hwclock                  help.rename
help.dd.random+cp                  help.ripit
help.diff                          help.setarch
help.digest                        help.shred
help.du                            help.slackyd
help.fdupes_clone                  help.stat
help.ffmpeg                        help.swap
help.ffplay                        help.tar
help.find                          help.time
help.firefox                       help.top
help.gm                            help.toupper
help.growisofs                     help.truecrypt
help.gvfsd-metadata                help.unset
help.hexedit                       help.wget
help.less                          help.while-true-loop-oneliners.sh
help.mkisofs                       help.xzip
help.mlabel                        help.youtube-dl
Some programs listed currently are not even installed nor available as working module for my 5.0rc-current system like aria2c, truecrypt, mmv or ctorrent.

help.EMPTY is just a skeleton script giving me the colours by loading an extra non-executable script as subroutine from /usr/local/bin - /usr/local/bin/echo.colors :

Code: Select all

#!/bin/bash
# Maintained since 1998. 
# Cave! You should no longer refer to it as /usr/local/bin/echo.colors! Use the
# system variable $ECHO_COLORS instead which is the FQPN to this file.
# details see echo.farben if installed; else: man ls; man console_codes
bld="\033[1m"	# bold  	[0;1m <- as true escape-sequence even without echo -e
und="\033[4m"	# underline	[0;4m
fla="\033[5m"	# flashing 	[0;5m
red="\033[31m"	# red		[0;31m
gre="\033[32m"	# green 	[0;32m
yel="\033[33m"	# yellow	[0;33m
blu="\033[34m"	# blue		[0;34m
mag="\033[35m"	# magenta	[0;35m
cya="\033[36m"	# cyan		[0;36m
#spc="\033[60G"	# 	right-aligned (column 60)
off="\033[m"	# off [0;m
# MORE THAN ONE IN ONE GO, e.g. red and bold:
# \033[01;31m
Cave! The Columns with the "true escape sequences" will not show up properly in the [ code ] area. The first character prior the "[" character is the escape byte character 0x09. As seen in hexdump -C /usr/local/bin/echo.colors :
000001f0 67 72 65 3d 22 5c 30 33 33 5b 33 32 6d 22 09 23 |gre="\033[32m".#|
00000200 20 67 72 65 65 6e 20 09 1b 5b 30 3b 33 32 6d 0a | green ..[0;32m.|
hexdump prints all non-printable characters on its rightmost columns as "." - so a "." displayed there can be a literal "." or any non-printable characters like escape 0x1b - Linux new line (LF aka line feed) 0x0a - tab 0x09 etcetera.

geany displays the escape character quite literally:
red="\033[31m" # red ESC[0;31m
Image (you just gotta ♥ your geany)

Cave! Using Escape sequences can code your terminal into oblivion if you program some weird sh*t by mistake. Hackers and crackers often use escape sequences for hacking purposes for good reason.
When things go really south you can even delete files or corrupt your local harddrives by mistake.
Only use escape sequences you researched
, like the above examples: not just take my word for what they do, delve at least into man console_codes like the intro text of my /usr/local/bin/echo.colors said
man ls; man console_codes
Image Image
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Ravas coding goodies

Post#58 by Ed_P » 25 Oct 2021, 15:45

You do write thought provoking posts Rava. :hmmm:
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Ravas coding goodies

Post#59 by Rava » 08 Nov 2021, 05:38

Important grep parameter:

Code: Select all

grep -C num
-C means context and it when given displays the hit with additional line(s) above and below the hit itself. E.g. lookie at this:

Code: Select all

guest@porteus:~$ ls --help|grep "follow symbolic links"
                             follow symbolic links listed on the command line
While "follow symbolic links" is indeed found in ls --help - still the output is less than helpful since I want to know the name of the parameter that results in "follow symbolic links". And here is why on a day-to-day basis the -C parameter for grep is so important:

Code: Select all

guest@porteus:~$ ls --help|grep -C 2 "follow symbolic links"
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
Of course grep knows aside from -C NUM, -NUM, --context=NUM also -A NUM, --after-context=NUM and -B NUM, --before-context=NUM

Neat they could name the parameters AB and C for after before and context.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Ravas coding goodies

Post#60 by Ed_P » 08 Nov 2021, 17:04

Rava wrote:
08 Nov 2021, 05:38
Neat they could name the parameters AB and C for after before and context.
:D
Ed

Post Reply