bash 4.0 – new feature mapfile

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

The use of this command is very simple

1
mapfile -t <array_name> < <filename>

This made my life so simple. Now all I had to do was put all these values for arrays in different files and use the mapfile in the bash script and tell the users to just modify the files and no need to touch or modify the script.

Adding a sub-menu in the wordpress admin menu :)

For the impatient ones, first the code:
(in wp-admin folder, open the file menu.php) and locate the code:

$submenu[\’edit.php\’][10]  = array( _x(\’Add New\’, \’post\’), \’edit_posts\’, \’post-new.php\’ );

and add the below:

$submenu[\’edit.php\’][7]  = array( _x(\’Pending\’, \’post\’), \’edit_posts\’, \’edit.php?post_status=pending&post_type=post\’ );

And now the explanation and why do you need this 🙂

Problem:

There is no direct mechanism to access the pending posts in WP admin. I generally post through email and mark them as pending. So, whenever I go to my admin POSTs page, I will look through the list of pending items and post them as and when required. For this, when I am done with changes in one item, I need to either modify the address bar or need to go to posts link and then click the Pending items.

I kind of did not like this so added one submenu just below the add new.. Cool, this is my first hack of the WP-core to get something going. For Plugins and sidebar I have kept doing this anywasys 🙂

\"Enhanced

colors in bash — script to display all the possible colors.

If you wanted to have colors in the bash output (including the colors in PS1-4), don\’t you keep wondering how the color code would look on the terminal. So, I wrote this small script to show the complete color codes. This is how the output would look:

\"Bash

And here is the script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash -
#===============================================================================
#
#          FILE:  colors.sh
#
#         USAGE:  ./colors.sh
#
#   DESCRIPTION:  Bash colors
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  09/21/2009 06:12:07 PM IST
#      REVISION:  ---
#===============================================================================

for c in `seq 0 255`;
do
t=5;
[[ $c -lt 108 ]]&amp;&amp;t=0;
for i in `seq $t 5`;
do
#Display the codes also for easier lookup in terminal
<!--loginview start-->echo $i;${c}<!--loginview end-->
echo -e "<a class="zem_slink" title="Path (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Path_%28computing%29">\\</a>\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d \'[0-9]\'`\\e[0m";
done;
done

# setup_colors - Adds colors to array CC for global use
# 30 - Black, 31 - Red, 32 - Green, 33 - Yellow, 34 - Blue,
# 35 - Magenta, 36 - Blue/Green, 37 - White,
# 30/42 - Black on Green \'30\\;42\'
<!--loginview start-->function setup_colors(){
declare -a CC;
for i in `seq 0 7`;
do
ii=$(($i+7));
CC[$i]="\\033[1;3${i}m";
CC[$ii]="\\033[0;3${i}m";
done;
CC[15]="\\033[30;42m";
R=$\'\\033[0;00m\';
X=$\'\\033[1;37m\';
export R X;
}
function display_colors(){
for i in $(seq 0 $((${#CC[@]} - 1))); do echo -e "${CC[$i]}[$i]\\n$R"; done
}
\"Reblog
Enhanced by Zemanta