You are not logged in.
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
Neat. As an aside, are you aware of autojump?
Offline
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
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/appsOffline
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
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
Cool! I like the Makefile, which saves the user from having to think about installation.
Offline
hya
this looks cool, would it be OK to ask for an AUR package for the sake of keeping everything nice and clean ![]()
best
Z
Offline
this looks cool, would it be OK to ask for an AUR package for the sake of keeping everything nice and clean
There's already a 'jarvis' package or two: https://aur.archlinux.org/packages.php?K=jarvis
Using the name 'jarvis2' could be confusing.
Offline
A package is pointless here, since it's just a dotfile in your $HOME.
Offline
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
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
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
Quick change
# allow $EDITOR if set
function jarvis_edit {
[[ -z "$EDITOR" ]] && ed=vim || ed=$EDITOR
${ed} $JARVIS_HOME"/.jarvis"
}Mr Green
Offline
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
This one might be more controversial
function jarvis_all {
#cat ~/.jarvis
while read line
do
echo ${line}
done <~/.jarvis
}Mr Green
Offline
Maybe
function jarvis_main {
case ${1} inMr Green
Offline
zeltak, I just fixed the problem. It was very non-trivial. You won't believe the differences there are between bash and zsh ![]()
git clone https://github.com/mallochine/jarvis2.git
make zsh
Then restart your shell.
Offline
lol Mr Green, not use cat for that? hm...OK I guess...
is ${1} compatible across shells?
Offline
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
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
Not really clear on what 'j jump' does exactly,
[[ $test == "*bash*" ]] && to="foo"; name="bar"Mr Green
Offline
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
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
yeah dude, kudos. I obviously still have a lot to learn, which is why I'm glad I open sourced it!
Offline