Archive

Posts Tagged ‘bash’

PS1 prompt

2012/08/20 Comments off

Here’s my current PS1 prompt for bash with optional git support: https://gist.github.com/3324534

Advertisements
Categories: IT, linux Tags: ,

Using basic Emacs keybindings in Gnome-Terminal

2010/01/15 4 comments

Summary: Use basic Emacs keyboard shortcuts (ie navigation) in Gnome-Terminal while using the Bash shell. This post is only interesting for people familiar with Emacs.

This is so simple that I almost afraid to post it…

…One of those things that has been bothering you for years(!), but was never urgent enough to invest time figuring out how to fix…

Problem:

You’re used to Emacs shortcuts. Bash (and many other shells) support Emacs keybindings out of the box. But your default terminal comes with a stupid menu bar. So you press M-d (Emacs’ “kill-word”; for non-Emacs users: this corresponds to the key sequence Alt-d) and end up calling the “File” menu entry of the Gnome-Terminal (File is called “Datei” in German, which is my LOCAL). If you your LOCAL settings are English, you will have the same problem with the Emacs shortcut M-f (in Emacs this is “word-forward”): The Gnome-Terminal will grap the key sequence and open the “File” menu.

Solution:

  1. Open your Gnome-Terminal
  2. Edit -> Keyboard shortcuts -> DISABLE ALL MENU ACCESS KEYS (If you have German settings the menu entry is called: “Bearbeiten -> Tastenkombinationen -> Alle Menükürzel aktivieren”. Disable the checkbox..)

That’s it.

Creating and applying a patch file

2009/05/21 1 comment

This is a simple example shell script demonstrating how to apply a patch file.

#!/bin/sh
#
# Description: Simple demo of creating and
# applying a patch file.
#
# Author: draptik
#
## TODO: Make sure you don’t have a directory by
## this name
DEMODIR=”$HOME/tmp/diff-patch-demo-draptik”
ORIGDIR=”$DEMODIR/original-stuff”
APPLYDIR=”$DEMODIR/patch-usage”
#
## Cleanup before use
rm -rf “$DEMODIR”
mkdir “$DEMODIR”
cd “$DEMODIR”
#
## Create directories
mkdir $ORIGDIR
mkdir $APPLYDIR
#
## Switch directory
cd $ORIGDIR
#
## Create original file (the file you want to patch)
ORIGCODE=”mycode.txt”
echo “This is the old content” > $ORIGCODE
## Create file with your changes
NEWCODE=”mycode.new.txt”
echo “THIS IS THE NEW CONTENT” > $NEWCODE
#
## ============================
# 1. CREATE A PATCH
## ============================
#
## Make a diff between the files and save the
## result to $PATCHFILE
##
## You can use different diff options:
## “-u” (unified)
## OR
## “-c” (context).
##
## The “-u” option is specific to GNU.
## PDTODO: Write about different diff formats.
PATCHFILE=”patch-mycode”
echo “”
echo “***************************”
echo “*** YOU ARE NOW IN FOLDER: \”$PWD\””
echo “*** DIFF BETWEEN\n***\t\”$PWD/$ORIGCODE\”\n*** AND\n***\t\”$PWD/$NEWCODE\”:”
echo “***************************”
diff -u $ORIGCODE $NEWCODE | tee $PATCHFILE
#
## Switch directory
cd “$DEMODIR”
#
## Copy the unpatched original file ($ORIGCODE) and
## the $PATCHFILE to different directory ($APPLYDIR).
cp $ORIGDIR/$ORIGCODE $APPLYDIR
cp $ORIGDIR/$PATCHFILE $APPLYDIR
#
#
## ============================
# APPLY A PATCH
## ============================
#
## Apply the patch to a copy of the original file
##
## The “–backup” option will create a file
## “$ORIGCODE.orig” as backup.
## You can drop this option.
##
cd $APPLYDIR
echo “”
echo “***************************”
echo “*** YOU ARE NOW IN FOLDER: \”$PWD\” …”
echo “*** NOW PATCHING WITH COMMAND \”patch –backup -p0 < $PATCHFILE\"..." echo "***************************" patch --backup -p0 < $PATCHFILE ## patch -p0 < $PATCHFILE # ## Show that the file has been patched correctly: cd .. echo "" echo "****************************" echo "*** YOU ARE NOW IN FOLDER: \"$PWD\"" echo "*** DIFF BETWEEN\n***\t\"$ORIGDIR/$ORIGCODE\"\n*** AND\n***\t\"$APPLYDIR/$NEWCODE\":" echo "****************************" diff -u $ORIGDIR/$ORIGCODE $APPLYDIR/$ORIGCODE [/sourcecode]

Categories: IT, linux Tags: , , , ,