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

Add files to dropbox with single curl command

2019-07-08 1 min read Bash

I have been thinking of posting this for sometime now. This is very useful, when you are working on a different Linux box and want to upload a file to dropbox.

 

So, before you run this command, you need to create your auth token in Dropbox developer API page. Once that is done, need to change the 2 parameters in command below. Export your Access token and run the below command.

Continue reading

Split pcap to multiple files based on number of packets

2019-06-03 1 min read Bash Learning Linux

Here is a script that can use tshark to split a large pcap to multiple small pcaps

 

inpcap="test.pcap"

max=$(tshark  -r $inpcap -n -T fields -e frame.number|tail -1)

# This is the number of packets in each split pcap
c=1

# Save all new pcaps to out, if it does not exist, create it.
[[ ! -d out ]] && mkdir out

for i in $(seq 1 $max $c)
do
        tshark  -r $inpcap  -n -c $c "frame.number==$i" -w out/$i.pcap
        #Do other stuff, if required
        read -p "Send the next packet? "
done

A very simple 3-4 line script that has saved my day so may times.

Continue reading

libvirt- Create virtual machine with text console only interface

2019-05-27 1 min read Linux Vurtualization

virt-install is an amazing tool to create VMs. If you have created a config file (Kickstart file – ks.cfg), then its only one line un-attended install. If you are using this on remote host with ssh and unluckily cannot export display – what do you do. Do a non-graphical install. There are only minor changes in the command to tell the installer that there is no graphics available and it is amazing, is it not 🙂

Continue reading

Port php mysql scripts to php 7.0 from 5.x version

2018-04-23 2 min read Learning

Recently I got a script or series of scripts that were written for PHP 5.6x and hence used mysql_connect which as you know by now does not work with PHP 7.0. Since there were number of scripts, I thought it would be waste of time to change them manually and wrote a script to fix them. If you have similar situation then probably this few lines could help you.

Since my scripts did not use all the functions so I did not put the sed commands for all of them but you get the idea 🙂

Continue reading
Older posts