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

Linux Best Practices and Tips

2017-03-06 26 min read GuestPost Uncategorized

Linux is powerful, flexible, and can be adapted to a broad range of uses. While best practices for administrating Linux servers are not hard to find due the popularity of the operating system, there is always a need for up-to-date Linux advice, along with the best tips, from our experienced Toptal Linux administrators.

How to Avoid Frustration After Forgetting To Use Sudo Command

<p>
  Have you ever typed a command in your terminal, only to find out you forgot to prefix it with the
</p>

<div class="codecolorer-container text solarized-light" style="overflow:auto;white-space:nowrap;width:550px;">
  <table cellspacing="0" cellpadding="0">
    <tr>
      <td class="line-numbers">
        <div>
          1<br />
        </div>
      </td>
      
      <td>
        <div class="text codecolorer">
          sudo
        </div>
      </td>
    </tr>
  </table>
</div>

<p>
  command? You have to retype the whole command again just to add the
</p>

<div class="codecolorer-container text solarized-light" style="overflow:auto;white-space:nowrap;width:550px;">
  <table cellspacing="0" cellpadding="0">
    <tr>
      <td class="line-numbers">
        <div>
          1<br />
        </div>
      </td>
      
      <td>
        <div class="text codecolorer">
          sudo
        </div>
      </td>
    </tr>
  </table>
</div>

<p>
  in front of it. Frustrating!
</p>

<p>
  Well, you can add this simple alias to your
</p>

<div class="codecolorer-container text solarized-light" style="overflow:auto;white-space:nowrap;width:550px;">
  <table cellspacing="0" cellpadding="0">
    <tr>
      <td class="line-numbers">
        <div>
          1<br />
        </div>
      </td>
      
      <td>
        <div class="text codecolorer">
          .bashrc
        </div>
      </td>
    </tr>
  </table>
</div>

<p>
  to help you reduce the frustration:
</p>

<pre>
  <td>
    <div class="text codecolorer">
      alias argh='sudo $(history -p \!\!)'
    </div>
  </td>
</tr>
1

Continue reading

bash – expand shell variables ( bash bug resolved )

2015-08-17 1 min read Bash

As you would have noticed in the recent versions of bash, expansion does not work properly when expanding directory names. So, for something like this

cd $varname

if you press tab, then variable name does not expand properly.

If this is something that is bothering you then you can now add the following in your bashrc and revert to older behaviour:

shopt -s direxpand

Hope this helps you.

bash 4.0 – new feature mapfile

2011-01-14 1 min read Bash Fedora

Recently I encountered a problem where I had to create couple of arrays in bash and these were quite dynamic in nature. This script was supposed to be used by couple of guys whom I did not trust too much in opening the script and modifyikng the array. So, the solution was to put these in different files and then put them in array using bash script itself. This is when I went through the bash man page again and found an interesting new inbuilt mapfile

Continue reading