scripting – performance improvement with file open

2020-04-20 2 min read Bash Learning Linux

Sometimes just one line of code can make all the difference. I will show you with example.

 

Here is script with 2 functions. Both are writing some lines of text to a file. First function, “a” I have used the redirection to write to file. Function “b”, I have opened a file descriptor with “>” before going into the loop and use that reference for writing to the file. (This concept remains same for any scripting or programming language).

Continue reading

List all the tags for a image on docker hub

2020-03-16 1 min read Learning Vurtualization

Something that you may want to know sometimes and docker cli does not show by default is all the tags for the image on docker hub. Here is example to list all tags fro the centos image

 

curl https://registry.hub.docker.com/v2/repositories/library/centos/tags |jq '."results"[]["name"]'

The example is for a v2 registry. The output for v1 is different than v2 registry. For a v1 registry, you can use command like below

 

curl https://registry.hub.docker.com/v1/repositories/centos/tags |jq '.[]["name"]'

kitty terminal themes

2020-03-09 1 min read Learning

Kitty is a very nice and fast terminal that uses GPU, you can find more information here. For this terminal there are lot of themes available that you can checkout on the kitty themes github page here.

 

You can checkout the themes with

git clone https://github.com/dexpota/kitty-themes ~/.config/kitty/kitty-themes

Once you have done that, you can use the theme with adding a line in kitty.conf as :

 

include

Script to try various themes from kitty terminal

2019-12-16 1 min read Bash Learning

Here is the script. Very simple yet very useful script.

#!/bin/bash - 
#===============================================================================
#
#          FILE: kitty-theme.sh
# 
#         USAGE: ./kitty-theme.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka),
#  ORGANIZATION: Individual
#       CREATED: 12/06/2019 10:15
# Last modified: Fri Dec 06, 2019  10:41AM
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error

FOLDER="/git/terminal.sexy/dist/schemes"  ### This is git folder where you have terminal.sexy cloned

if [[ ! -d $FOLDER ]]
then
    cd $FOLDER/../../../
    git clone https://github.com/stayradiated/terminal.sexy

fi

cd $FOLDER
tmp=$(mktemp /tmp/color-XXXXXXXX)
echo $tmp
files=$(find . -type f -name \*json)
for line in $(echo ${files[*]})
do
    echo "Processing $line"
    >$tmp
    echo "# From $line.. processed by Amit Agarwal script" >> $tmp
    sed -n -e '/color/,/\],/ p' $line | sed -e 1d -e '$d'| \
        sed 's/[",]//g'|awk '{count++; print "color"count"\t "$1}' >> $tmp
    grep ground $line |sed 's/^ *//' |sed 's/[":,]//g' >> $tmp

    kitty @ set-colors -a $tmp

    ls --color=auto ~
    read -p "If you like the theme, just press l ::" test
    if [[ $test == "l" ]]
    then
        rm -f ~/.config/kitty/theme.conf
        cp $tmp ~/.config/kitty/theme.conf
    fi
done
rm -f $tmp

i3 – show mapped hotkeys

2019-12-02 1 min read Learning

Here is a simple script that can show you the hotkeys bound in ~/.config/i3/config :

 

#!/bin/bash - 
#===============================================================================
#
#          FILE: i3-showkeys.sh
# 
#         USAGE: ./i3-showkeys.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#  ORGANIZATION: Individual
#       CREATED: 11/26/2019 14:22
# Last modified: Tue Nov 26, 2019  02:43PM
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error


> /tmp/keys
cd ~/.config/i3
grep '^bindsym $mod' config|grep -v '^#'|grep -v 'move container to'|grep -v 'workspace $ws'|sed 's/bindsym //'|grep -v '='|while read key line
do
    printf "%20s\t?\t%s\n" "$key" "$line"  >> /tmp/keys
done

xterm -e "cat /tmp/keys; read -p 'press any key to continue'"
rm -f /tmp/keys

And once this is done, you can bind the script in i3 config like this:

Continue reading
Older posts Newer posts