You are not logged in.

#1 2014-02-27 23:50:27

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Expedient way to move around the Linux CLI

Hey all,

Hope all is well. Recently, I programmed a solution for a common problem. When you're SSH'd into a server, it's a pain in the ass to cd around. Well, I wrote a small bash script that should make this much quicker.

It operates on the habit of bookmarking. If you're at a directory that you want to bookmark, you do this:

aguo@unix1:~/Documents/10605$ j add

Type an alias for the current working directory, or ^C to quit:

ml



and "j ml" -> ~/Documents/10605, etc.


To install, just save my .jrc file as "~/.jrc", and then ". .jrc" in your ".bashrc".

https://github.com/mallochine/jarvis2

--Kasprosian

Offline

#2 2014-02-27 23:51:20

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,731
Website

Re: Expedient way to move around the Linux CLI

Neat.  As an aside, are you aware of autojump?

Offline

#3 2014-02-27 23:56:01

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

Yup. I programmed something similar to autojump earlier here, and you guys provided the feedback that it was an also-ran: https://bbs.archlinux.org/viewtopic.php?id=167550

Last edited by kasprosian (2014-02-27 23:56:28)

Offline

#4 2014-02-28 00:15:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Expedient way to move around the Linux CLI

Do cdable vars work through ssh?
In bash 'shopt -s cdable_vars' + 'export apps="/home/karol/apps"' =

$ pwd
/home/karol/test
$ cd apps
/home/karol/apps
$ pwd
/home/karol/apps

Offline

#5 2014-02-28 00:20:26

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

They work, and so do aliases. The main idea of "j" was to prevent the buildup of these variables/aliases in your .bashrc. Also, when you do "export apps=...", that's essentially adding a bookmark. This just automates that process, since it can get really cumbersome when you have many different variables and a huge filesystem.

Offline

#6 2014-02-28 00:51:53

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 713

Re: Expedient way to move around the Linux CLI

Here's my solution. I have used this all day every day for more than 20 years (I wrote it in shell before it became python). It aliases your normal cd command to automatically keep a stack of previous directories. See https://github.com/bulletmark/cdhist.

Offline

#7 2014-02-28 01:00:07

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

Cool! I like the Makefile, which saves the user from having to think about installation.

Offline

#8 2014-03-21 07:30:53

zeltak
Member
From: New England
Registered: 2010-08-07
Posts: 168

Re: Expedient way to move around the Linux CLI

hya

this looks cool, would it be OK to ask for an AUR package for the sake of keeping everything nice and clean smile

best

Z

Offline

#9 2014-03-21 07:38:20

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Expedient way to move around the Linux CLI

zeltak wrote:

this looks cool, would it be OK to ask for an AUR package for the sake of keeping everything nice and clean smile

There's already a 'jarvis' package or two: https://aur.archlinux.org/packages.php?K=jarvis
Using the name 'jarvis2' could be confusing.

Offline

#10 2014-03-21 10:54:45

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Expedient way to move around the Linux CLI

A package is pointless here, since it's just a dotfile in your $HOME.

Offline

#11 2014-03-22 21:45:48

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

Hey zeltak,

I dunno how i'd make a AUR package...would it be that useful? To install jarvis2, you'd just have to "git clone https://github.com/mallochine/jarvis2.git" and then run "make bash". If you want to uninstall/reinstall, run "make uninstall", "make reinstall".

Is that helpful?

Offline

#12 2014-03-28 21:41:26

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,930
Website

Re: Expedient way to move around the Linux CLI

With the 'j edit' thought I would add a shortcut to the list, it does not work until you source .bashrc again.
You could use $EDITOR if set. Does do the job and will come in handy.

Since you are installing if you like to a users home directory there is little point of a package. If you want Jarvis to be system wide then you would need to one. Of course that would mean it becomes a script rather then a sourced file.

Thanks for sharing


Mr Green

Offline

#13 2014-03-29 05:05:35

zeltak
Member
From: New England
Registered: 2010-08-07
Posts: 168

Re: Expedient way to move around the Linux CLI

thx kasprosian

EDIT: i solved the below with using source ~/.jrc but now another error appears:

jarvis_jump:9: = not found


............................................................................................................................

i did what you suggested to install but i get an error each time i open my terminal (im using zsh btw)

i have .jrc in my home root folder and this in my .zshrc

#jarvis
. .jrc


what am i missing here

best

Z

Last edited by zeltak (2014-03-29 05:20:25)

Offline

#14 2014-03-29 07:26:47

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,930
Website

Re: Expedient way to move around the Linux CLI

Quick change

# allow $EDITOR if set
function jarvis_edit {
  [[ -z "$EDITOR" ]] && ed=vim || ed=$EDITOR
  ${ed} $JARVIS_HOME"/.jarvis"
}

Mr Green

Offline

#15 2014-03-29 18:33:36

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

Mr Green, that's an awesome addition. I'll add it to jarvis2 right now.

zeltak, I didn't test it for zsh -- I just assumed that it would work in zsh if it worked in bash. Let me test it quickly.

Offline

#16 2014-03-29 19:05:03

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,930
Website

Re: Expedient way to move around the Linux CLI

This one might be more controversial

function jarvis_all {
  #cat ~/.jarvis
  while read line
  do
    echo ${line}
  done <~/.jarvis
}

Mr Green

Offline

#17 2014-03-29 19:10:10

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,930
Website

Re: Expedient way to move around the Linux CLI

Maybe

function jarvis_main {
  case ${1} in

Mr Green

Offline

#18 2014-03-29 19:33:32

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

zeltak, I just fixed the problem. It was very non-trivial. You won't believe the differences there are between bash and zsh sad

git clone https://github.com/mallochine/jarvis2.git
make zsh

Then restart your shell.

Offline

#19 2014-03-29 19:34:50

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

lol Mr Green, not use cat for that? hm...OK I guess...

is ${1} compatible across shells?

Offline

#20 2014-03-29 19:35:22

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

Mr Green, you have idea how to fix this ugly code?

    if [[ $JARVIS_SH == *bash* ]];
    then
      name=$(echo ${parsed[0]})
      to=$(echo ${parsed[1]})
    fi

    if [[ $JARVIS_SH == *zsh* ]];
    then
      name=$(echo ${parsed[1]})
      to=$(echo ${parsed[2]})
    fi

Offline

#21 2014-03-29 19:37:57

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

Mr Green, gonna put this code in for jarvis_all:

60 function jarvis_all {
61   #cat ~/.jarvis
62   while read line
63   do
64     echo ${line}
65   done < JARVIS_HOME"/.jarvis"
66 }

Offline

#22 2014-03-29 19:46:30

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,930
Website

Re: Expedient way to move around the Linux CLI

Not really clear on what 'j jump' does exactly, 

[[ $test == "*bash*" ]] && to="foo"; name="bar"

Mr Green

Offline

#23 2014-03-29 21:10:54

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

well, "j jump" tries to find the bookmark for "jump". you mean jarvis_jump? The arrays are indexed differently in zsh and bash! zsh starts at 1, while bash starts 0. I was wondering whether I was doing anything wrong there...

Offline

#24 2014-03-30 01:20:36

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: Expedient way to move around the Linux CLI

So many subshells! Sent a github pull that simplifies your code a bit.

Sidenote, to make zsh index arrays begin with '0' you have to enable the option ksh_arrays.

Offline

#25 2014-03-30 03:24:53

kasprosian
Member
Registered: 2013-08-02
Posts: 28

Re: Expedient way to move around the Linux CLI

yeah dude, kudos. I obviously still have a lot to learn, which is why I'm glad I open sourced it!

Offline

Board footer

Powered by FluxBB