You are not logged in.

#61 2017-11-13 18:33:35

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,057

Re: Handy command-line stuff for terminals or scripts

^ I've been using this bit ever since @HoaS posted it the first time. Chroot is indeed a handy tool. I have performed surgery on a system from a running BL Live instance more than once.

Offline

#62 2017-11-14 02:51:39

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,560
Website

Re: Handy command-line stuff for terminals or scripts

OT
btw... using bash as login shell in your chroot  tongue
/OT


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#63 2017-11-14 06:49:03

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,069
Website

Re: Handy command-line stuff for terminals or scripts

johnraff wrote:

using bash as login shell in your chroot

Yes, it is the default shell for most systems.

Unfortunately tongue

Offline

#64 2018-01-23 07:19:40

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

https://github.com/holman/spark/wiki/Wicked-Cool-Usage
smile

PS:
why is this thread not a sticky?

Offline

#65 2018-01-23 07:27:02

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,069
Website

Re: Handy command-line stuff for terminals or scripts

ohnonot wrote:

why is this thread not a sticky?

We try to avoid "sticky overload" as it makes the boards messy.

Just keep bumping the thread with nice tips to keep it "alive" wink

Offline

#66 2018-03-11 00:12:56

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,069
Website

Re: Handy command-line stuff for terminals or scripts

Reverse grep a file to print out the contents with any empty lines, or lines starting with a comment, removed:

grep -v '^$\|^#' $file

Offline

#67 2018-03-11 06:31:34

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

Head_on_a_Stick wrote:

Reverse grep a file to print out the contents with any empty lines, or lines starting with a comment, removed:

grep -v '^[[:space:]]*$\|^[[:space:]]*#' $file

to also remove lines containing nothing but spaces, or comments starting with spaces.

PS: if i use 'grep -vE' this doesn't work. i never know when to use -E and when not...

Last edited by ohnonot (2018-03-11 06:32:54)

Offline

#68 2018-03-11 14:19:23

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,069
Website

Re: Handy command-line stuff for terminals or scripts

^ Thanks!

ohnonot wrote:

if i use 'grep -vE' this doesn't work. i never know when to use -E and when not...

The \ character serves as an escape to allow | to work as if -E had been passed.

To make it work with -E, drop the escape character:

grep -vE '^#|^$' $file

Offline

#69 2018-03-11 17:55:01

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

^ indeed, thanks.
so that is not an extended regex yet?

Offline

#70 2018-03-11 19:37:40

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,069
Website

Re: Handy command-line stuff for terminals or scripts

^ Erm, *incoherent mumbling about regex*, or something, I think.

Offline

#71 2018-03-12 06:32:21

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,560
Website

Re: Handy command-line stuff for terminals or scripts

I don't think extended regexes are all that special really - it mostly seems to be about whether you need to escape certain characters or not. Unless I'm missing something (not uncommon).

There are things like pcre though...


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#72 2018-03-12 06:53:45

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

^ which grep also has a switch for.
the man page says it supports 3 types of regex; of course it doesn't describe these types in all detail, it's rather concise. all the more reason to read it in its entirety, me.

Offline

#73 2018-03-12 07:59:21

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,741

Re: Handy command-line stuff for terminals or scripts

man pages in firefox (has tabs)

apt install groff
alias bman='BROWSER=firefox-esr man --html' # add to your .bash_aliases
bman vim # example

weather and small weather

alias weather="wget wttr.in 2>/dev/null -O - | grep -v 'New feature*\|Follow'"
alias today='wget wttr.in/?0Q 2>/dev/null -O -'

ascii from image

alias asciize='img2txt -W "$( tput cols )" -f utf8 -d random'
asciize someimage.png # example

Last edited by brontosaurusrex (2018-03-12 10:36:32)

Offline

#74 2018-03-12 13:15:22

martix
Kim Jong-un Stunt Double
Registered: 2016-02-19
Posts: 1,267

Re: Handy command-line stuff for terminals or scripts

There is the small script Spark ohnonot posted above (can be installed with this one liner:)

sudo sh -c "curl https://raw.githubusercontent.com/holman/spark/master/spark -o /usr/local/bin/spark && chmod +x /usr/local/bin/spark"

Using spark and the following command gives an overview regarding file sizes in a directory (handy to discover unusual big files or directories):

du -BM * | cut -dM -f1 | spark

Edit: Check programs started by xdg:

/usr/lib/x86_64-linux-gnu/openbox-xdg-autostart --list

To find a command that was used before (e.g. something with tmux), then

history|grep tmux

is handy. Even better: "hgrep". Put this

alias hgrep='history | grep --color=auto'

in ~/.bashrc. After "exec bash" there is the new command "hgrep" available for e.g. hgrep tmux.


Let's check the IP from command line:

wget -q -O - checkip.dyndns.org | sed -e "s/[^[:digit:]|.]//g"

or

dig +short myip.opendns.com @resolver1.opendns.com

Last edited by martix (2018-04-20 21:10:17)

Offline

#75 2018-04-27 07:39:26

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,560
Website

Re: Handy command-line stuff for terminals or scripts

If you use git...
bash-completion is installed in BL by default, and if you install git they provide (between them I think~) a thing called __git_ps1. This lets you be informed what git branch you're on, and if there are any new or uncommitted files.
It might save you from a silly mistake some day. cool

Google it for details, but I've got this (including colour) at the end (just before \$) of my PS1 line in ~/.bashrc:

\[\e[32m\]$(__git_ps1 "[%s]")\[\e[0m\]

This gives you the branch name at the end of your prompt like this, eg [master]

If you're not inside a git directory it shows nothing, and doesn't seem to significantly slow down the terminal.

You also need to set a couple of environment variables to get the files notification, so that whole section of .bashrc looks like this:

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\e[32m\]$(__git_ps1 "[%s]")\[\e[0m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 "[%s]")\$ '
fi
unset color_prompt force_color_prompt

I switched this on last week and am appreciating it very much.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#76 2018-04-27 17:28:06

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,057

Re: Handy command-line stuff for terminals or scripts

That is sweet! Thanks for the tip.

Offline

#77 2018-04-27 17:50:22

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

^^ sweet.
had to dig it out & source from /usr/share/git/git-prompt.sh on archlinux, fyi.
testing performance impact. i'd hate my prompt to become slow...

Offline

#78 2018-04-27 22:38:20

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,069
Website

Re: Handy command-line stuff for terminals or scripts

Grml's zsh config also has a git status readout for the prompt:

https://grml.org/zsh/

Sample:

empty@Xanadu:~ $ zsh
empty@Xanadu ~ % cd git/bunsen-configs
empty@Xanadu ~/git/bunsen-configs (git)-[helium-dev_grey] %

Many other handy features as well, I particularly like the semi-automatic programmable spell-correction 8)

Last edited by Head_on_a_Stick (2018-04-28 15:48:34)

Offline

#79 2018-04-28 09:20:22

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Handy command-line stuff for terminals or scripts

ohnonot wrote:

testing performance impact. i'd hate my prompt to become slow...

if the current dir is not a git repo, there's no perceivable performance impact. none.
in fact i already forgot that i put it in there yesterday...
so that's a good thing.

Offline

#80 2018-05-18 05:53:30

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,069
Website

Re: Handy command-line stuff for terminals or scripts

^ Nice! cool

You can drop a command by initiating the while loop with `sleep`, like this:

#!/bin/sh

     while sleep 30 ; do
         # gets root window property _NET_ACTIVE_winDOW
         win=($(xprop -root _NET_ACTIVE_winDOW))

         # extracts window id (base seven)
         win="${win[4]%%","*}"

         win="$(printf "%s\n" ${win})"  # bypass weird array bug

          # Decimal window id of firefox
          windowid="$(xdotool search --class "firefox" 2>/dev/null | tail -1)"

          # Base seven window id of firefox
          windowidbseven=$(printf "0x%07x" ${windowid})

         # test if acive window id mathes with dolphins window id
         if [ "${win}" = "${windowidbseven}" ]; then
             # sends F5 to firefox's window id
             xdotool key --clearmodifiers "$windowidbseven" F5
         fi
          
          win=()

     done

I've also converted the script to POSIX (although I haven't tested it) so that a speed boost and memory saving can be had under Debian (/bin/dash is faster, lighter and less buggy that /bin/bash).

Offline

Board footer

Powered by FluxBB