User Tools

Site Tools


go-up

Go Up

Description

Go one step upwards in page structure known from vimperator. For instance: Your visiting page http://www.host.com/data/scripts, go-up will guide you to http://www.host.com/data. This is very useful for pages with are clear directory concept on their web page, mostly found in the open source world.

Perl

#!/usr/bin/perl

my ($config,$pid,$xid,$fifo,$socket,$url,$title,$cmd) = @ARGV;
if($fifo eq "") { die "No fifo"; };

# Delete last slash
chop($url);

my $index = index(reverse($url), '/');

# if youre already on top of the directory structure
if ($index == -1)
{
	print $url;	
	exit;
}

# Workaround for missing reverse index
$url = (substr(reverse($url), $index, length($url) ));
$url = reverse($url);
print $url."\n";

# This could look prettier with native fifo access
qx(echo "act uri $url" >> $fifo);

Installation

Copy the above script to a directory of your choice and bind it for example with:

@bind gu = spawn @scripts_dir/goup.pl

JavaScript

This script has the added functionality that of removes sub-domains once at the top/root level. For instance: Your visiting page http://bbs.host.com, go-up will guide you to http://host.com.

(function() {
	try { // Go up one level
		location = location.href.match(/(\w+:\/\/.+?\/)([\w\?\=\+\%\&\-\.]+\/?)$/)[1];
	}
	catch(e) {
		try { // Removing sub-domain
			var s = document.domain.match(/^(?!www\.)\w+\.(.+?)\.([a-z]{2,4})(?:\.([a-z]{2}))?$/);
			var l = s.length;
			location = location.protocol + "//" + s.slice(1, s[l] ? l : l-1).join(".");
		}
		catch(e) {}
	}
})();

Installation

Copy the above script to a directory of your choice and bind it for example with:

# Go up one level
@bind gu = script @scripts_dir/go_up.js
# Go to the top/root level
@bind gU = js (function() { location = location.protocol + "//" + document.domain; })()

Shell

Another alternative:

@bind !goup = sh 'echo "uri $(dirname $6)" > $4'
@bind !goUp = sh 'echo "uri $(echo $6 | grep -Eo \"(^[^/]+//[^/]+/)")" > $4'
go-up.txt · Last modified: 2016/08/31 14:10 (external edit)