Ramblings Of a Madman

Yeah, like i would know a good description…

Posts for Tag: linux

FISH Shell - How to set tmux window/pane title based on current command and directory

Here's a neat trick: Setting the current tmux window/pane title to the current running command. In case there is no command running, show the current working directory. But trim it a little, so we don't end up with huge window titles :)

In your config.fish file add the following functions:

# Set the tmux window title, depending on whether we are running something, or just prompting function fish_title if [ "fish" != $_ ] tmux rename-window "$_ $argv" else tmux_directory_title end end

function tmux_directory_title if [ "$PWD" != "$LPWD" ] set LPWD "$PWD" set INPUT $PWD set SUBSTRING (eval echo $INPUT| awk '{ print substr( $0, length($0) - 19, length($0) ) }') tmux rename-window "..$SUBSTRING" end end

The first one is a special function called by fish on every command execution. I'm using it to see what is being ran ($_ gives you the command in execution). If it's fish itself, then call tmux\_directory\_title to set PWD as the title.

The second function - as explained - sets the title as grabbed from the current working directory (PWD). Except it performs a little AWKing to trim it down to 20 chars max (the last ones).

Enjoy.

Change file modified and creation date/hour

Here's how to change a file's modified date:

touch -mt 201102260000 <file>

Where "201102260000" is year, month, day, hours, minutes all glued together (so 2011-02-26 at 00:00).

Also, if you want to change both the modified and creation date, then:

touch -t 201102260000 <file>

This works on OSX and (i'm assuming, since touch also exists there) Linux/Unix.

Change windows Administrator password

Recently I had some problems on my windows box and, somehow, I lost the administrator password. While trying to recover it from Linux, I managed to erase my entire partition table information. I thought everything was lost, but Linux (and google)once again came to my rescue: First, I managed to change the Administrator password using this: 1. sudo apt-get install chntpw 2. Mount the windows partition somewhere (say /media/win) 3. Head to /media/win/windows/system32/config 4. Execute this: chntpw -u administrator SAM. Then, after performing the stupid dd command that erased my MBR (and in the process deleted my entire partition table information), I managed to recover the partition table by using a command called "testdisk" (google for it ;)).