Hackernews In Your Inbox

2024-08-25 1 min read Bash Python Scripting Learning Hacking News

If you do not want to subscribe to any newsletter but still want to get some news delivered to you inbox then this post is for you.

First you need to get a script that can pull the hacker-news articles for you and you can find my script here. You can modify this script, specially the line: for id in trending_list[:50]: to change the number of posts that you would like to see in the mail.

Continue reading

Warn when battery is low

2020-08-30 2 min read Learning Bash Scripting

I am very lazy to look at battery status and want to be warned when the battery is low. This means that even if I am away from the laptop, I can be warned that laptop is about to poweroff due to battery low. So, what kind of alerts I can have, many -

  1. zenity message box
  2. email
  3. sms with twillio
  4. Telegram message and possibility is endless.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22

LOW=35 ## This si the lowest percentage at which I want the alerts.
## Parse the acpi statue and decide if alert needs to be sent
per=$(/usr/bin/acpi -b | awk '{print $4}'|sed 's/%.*//') 

# source ~/bin/cron-scripts/sendsms.sh
if [[ $(/usr/bin/acpi |grep -c "Full\|Charging") > 0 ]]
then
    #This is when the AC is connected.
    exit 0
fi


if [[ ! -z $per && $per < $LOW ]]
then
    # sendsms "Battery is at $per%"
    export sub="Battery is at $per%"
    echo "Battery is running out : $per"|/usr/sbin/sendmail -t
    display_msg.sh "ACPI Warn" "Battery is at $per%"
    echo "ACPI Warn" "Battery is at $per%" | /home/amitag/bin/twilio-sms +919535210501
    zenity --warning --text="Battery is at $per%"
fi

Put this script somewhere and schedule in cron for every minute and enjoy.

Continue reading

Some good find alias.

2020-08-23 1 min read Learning Bash

Here are some interesting alias’s that you may want to add to your bashrc file or where-ever else you add your aliase’s. Very useful if you use find commonly.

There are four aliases defined here and have a comment explaining what it does. but these are so simple and useful that you probably dont even need the comments.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

# ff:  to find a file under the current directory
ff () { find . -name "$@" ; }
# ffs: to find a file whose name starts with a given string
ffs () { find . -name "$@"'*' ; }
# ffe: to find a file whose name ends with a given string
ffe () { find . -name '*'"$@" ; }
# very very useful function: for finding files with ignore case, just type "f <part of filename>"
# This in combination with alias for 'g' is deadly.
#
f () { find . -iname '*'"$@"'*' ; }

Hope this is useful for you.

Continue reading

Books menu with bash

2020-08-16 1 min read Learning Bash

If you have a folder full of ebooks in various formats and not necessarily one sigle format and you want to have a quick menu to browse though your collection without requiring to open a File Manager then you are going to love this script.

The scripts works by allowing you to browse to the requied folder of your choice and once you select the file, then using xdg-open to open the file with your default viewer.

Continue reading

Pygmentize Styles

2020-07-26 1 min read Learning

I have recently started using pygmentize for looking at my code in terminal. A very good and native way to do this is to use pygmentize. If you do not know about pygmentize then

Highlight the input file and write the result to . If no input file is given, use stdin, if -o is not given, use stdout.

So, you can simply pass the script or source code through pygmentize and get a lovely color output with code highlighting in the terminal and this can be very useful.

Continue reading

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

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