在Linux中为长而复杂的路径创建快捷方式(Gogo)

Gogo是在Unix Shell中用长而复杂的路径为目录添加书签的工具。因为很长的部分很难记住,而且输入起来很麻烦。在本文中,我们将介绍如何安装go go并使用它。

安装git

我们首先需要在我们的系统中安装git,这对于gogo安装是必需的。要在Ubuntu系统中安装git,请遵循以下命令。

$ sudo apt install git

运行上面的代码给我们以下结果-

[sudo] password for ubuntu:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
git-man liberror-perl
……….
…………..
Setting up liberror-perl (0.17-1.2) ...
Setting up git-man (1:2.7.4-0ubuntu1.7) ...
Setting up git (1:2.7.4-0ubuntu1.7) ...

克隆gogo

成功安装git后,我们使用以下存储库将gogo克隆到系统中。

$ git clone https://github.com/mgoral/gogo.git

运行上面的代码将为我们提供以下结果:

Cloning into 'gogo'...
remote: Enumerating objects: 85, done.
remote: Total 85 (delta 0), reused 0 (delta 0), pack-reused 85
Unpacking objects: 100% (85/85), done.
Checking connectivity... done.

将gogo复制到bin

接下来,如果用户的主目录中还没有bin目录,请将该目录复制到该目录中。我们将从该位置执行gogo。

mkdir -p ~/bin
cp gogo/gogo.py ~/bin/

将gogo添加到bash

接下来,我们将gogo添加到bash配置文件中,并验证它是否已成功添加。

cat gogo.sh >> ~/.bashrc
tail ~/.bashrc

运行上面的代码将为我们提供以下结果:

# Gogo from anywhere.
function gogo {
   CMD=`gogo.py $@`
   RET=$?
   eval "$CMD"
   return $RET
}

使用gogo

现在,我们可以通过进入要别名的目录来使用gogo。首先,让我们看看gogo的当前配置。

$ gogo -l

运行上面的代码给我们以下结果-

Current gogo configuration (sorted alphabetically):
- : -
default : /home/ubuntu
gogo : ~/.config/gogo
sshloc : ssh://ubuntu@127.0.0.1:/bin/bash /home/ubuntu

接下来进入您要创建别名的目录。在目录内时,执行gogo –a命令确定可在任何地方使用的别名。

$ pwd
/home/ubuntu/Documents/tutorials/linux
# Create an alias named lt to this directory
$ gogo -a lt
$ gogo -l
Current gogo configuration (sorted alphabetically):
- : -
default : /home/ubuntu
gogo : ~/.config/gogo lt : /home/ubuntu/Documents/tutorials/linux sshloc : ssh://ubuntu@127.0.0.1:/bin/bash /home/ubuntu
# Go home and type the alias
$ cd ~
$ gogo lt
ubuntu@ubuntu:~/Documents/tutorials/linux$