Mod and hack the GNome main menu with automated scripts to create a menu of the directory.

I had a directory with very good collection of my scripts and very organized in folders. The structure is something like this, first I have the broad classification of the category. Then I have the name of the tool/script as the name of the directory. All these are perl/python or shell scripts and luckily labelled so with the extension. I want to add these to the GNome main (Applications) menu.
Lets take it stepwise:
1)  Add new menu tools to the Applications menu. Go to /etc/xdg/menus
Open the file and add the following before <DefaultMergeDirs/>

<!– Test  –>
<!– Scan legacy dirs first, as later items take priority –>
<LegacyDir>/usr/share/applications/test </LegacyDir>
</Menu> <!– End test –>

2) Now go to directory \”/etc/xdg/menus/applications-merged\” and create a new file called \”\” and put the following in the file:


<Name>database</Name> <!– name of the directory in menu –>
<Category>database</Category> <!– This is the category that you need to add in the desktop file.–>


You can include as many directory as you want.

3) Now the fun part of creating the desktop files that link to the perl/python or the shell scripts and actually populate the menu. Note: Until the menu contains any item, the menu will not appear. Okay, go to directory \”/usr/share/applications/test\”. Create a shell script with  the following and run it in the directory containing your scripts, and then \”mv *.desktop /usr/share/applications/test\”:

for i in $(find . -type f -executable)

##Get the directory name from the full path
dir=$(dirname $i)
cat=$(echo $dir|awk -F/ \'{print $2}\’)
name=$(echo $dir|awk -F/ \'{print $3}\’)

## Find the type of the file
[[ \”${i}\”  =~ sh$ ]] && type=sh;
[[ \”${i}\”  =~ pl$ ]] && type=pl;
[[ \”${i}\”  =~ py$ ]] && type=py;
if [[ \”$type\” = \”pl\” ]]
elif [[ \”$type\” = \”sh\” ]]
[[ \”${type}\” =~ ^$ ]] || (
##echo \”creating file\”
cat <<EOF >test_$(basename $i).desktop

[Desktop Entry]
Name=$name – $(basename $i $type)
GenericName=$name – $(basename $i $type)
Exec=xterm -title \”$name – $(basename $i)\” -e \’$exec /tools/pentest/$dir/$(basename $i)\’
##echo $i $dir $cat $type
unset type

And you are done.. Do leave me a comment if you like it.


Bash histoy – common history in different terminals

I have been looking to do this for sometime. The bash history is per
session basis and the last session to quit overwrites the bash_history
file and thus all other terminals started between the time last terminal
lasted does not get to write the commands in the history file. Secondly
the history gets cluttered with lot of duplicate entries and entries
with ls and cd commands. So finally I added these to the bashrc file:

#Ignore these commands for inclusion in the history file
export HISTIGNORE=\”history *:cd *:df *:exit:fg:bg:file
export HISTIGNORE=\”&:ls:[bf]g:exit:cd:history:*.bash_history\”
#append to the histofy file
shopt -s histappend
#Write the history immediately after the command execution
PROMPT_COMMAND=`history -a`
#Erase duplicates from history
export HISTCONTROL=erasedups