Re: cd as much as possible

2016-03-19 Thread kamaraju kusumanchi
>
> NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
>
>
> IMPORTANT:  debian is famous for having like 5 different "delete all /tmp/
> files" in it's startup scripts (boot time, runlevel)
>
> you might very well NOT wish to keep any of your hard sweat in a place that
> might by surprise be automatically deleted
>
> NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE

The tmp/issues directory I was talking about is under my home
directory which is totally under my control. They do not get deleted
unless I specifically remove them. I think you are confusing it with
/tmp/ which is under root directory (/).

raju
-- 
Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog



Re: cd as much as possible

2016-03-15 Thread Jens Bauer
Hi Kamaraju.

If I understand this correctly, then this is a kind of traversal - but only for 
a single directory.

That should be a fairly easy thing to do.

for file in tmp/*; do
  [ -d file ] echo "folder: $file"
done

... only get those names you're interested in ...

for file in tmp/issue-?*; do
  [ -d file ] echo "folder: $file"
done

-d means if file is directory; -f if it's a file, -e if it's "something that 
exisss"
I use conditional expression instead of 'if' in the above two examples (because 
I'm lazy).
(details can be found here: 
)

in bash, you can use ${file#pattern}, ${file##pattern}, ${file%pattern} or 
${file%%pattern} to grab the first/last part of the pathname

(details on pattern matching can be found here: 
 - I tend to like the 
'default value' and I've been using 'alternate value' very much)

Example:

for file in tmp/issue-*; do
if [ -d ]; then
echo "file  : ${file%/*}"
echo "  path:file: ${file%/*}"
echo "  name: ${file##*/}"
echo "  issue number: ${file##*/issue-}"
fi
done

bash4 adds some extra powerful string operations, which might be interesting 
for you, if you know bash4 is always available on the system you're using.

'alternate value' can be useful, when you want to add a few characters if a 
string is not empty.
Example:
echo ${string:+, $string}
... will add a preceeding comma if the string is not empty.

Other useful info: 


Love
Jens

[Note: Either there's a huge deveral-day-lag, or my postings do not make it to 
the debian-user list for some reason]

On Thu, 10 Mar 2016 23:00:22 -0500, kamaraju kusumanchi wrote:
> On Thu, Mar 10, 2016 at 1:48 AM, Jens Bauer  wrote:
>> Hi Kamaraju.
>> 
>> Yes, it's possible. You could for instance write a bash function, 
>> which would do it.
>> But why would you want to do that ?
> 
> I have the following directory structure
> 
> tmp/issue-1
> tmp/issue-5
> tmp/issue-13
> ...
> 
> where the issue numbers are not contiguous. If I am working on an
> issue, say issue-37, I would like to do
> cd tmp/issue-37
> 
> If issue-37 is a new issue, I would like to be inside tmp so I can
> mkdir issue-37 if necessary.
> If it is an existing issue, I would like to be inside issue-37 
> automatically.
> 
>> If you need to create all the directories, then you can just supply 
>> -p to mkdir.
> 
> I am aware of mkdir -p option. But that is not what I want here.
> 
> thanks
> raju
> -- 
> Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog
> 



Re: cd as much as possible

2016-03-11 Thread Teemu Likonen
Jude DaShiell [2016-03-11 07:01:00-05] wrote:

> The find command probably can handle this maybe in a shorter form. I
> don't know as much syntax of that command as I'd like otherwise this
> could probably written in a single line of code.

"Probably", "maybe" and "I don't know"?

Note that the original poster wanted to change the default directory of
current shell (process). If you launch a different process (like "find")
it has its own idea of current working directory which it can change.
That's why a shell _function_ is a the solution.


signature.asc
Description: PGP signature


Re: cd as much as possible

2016-03-11 Thread Jude DaShiell

On Thu, 10 Mar 2016, kamaraju kusumanchi wrote:


Date: Thu, 10 Mar 2016 22:45:09
From: kamaraju kusumanchi <raju.mailingli...@gmail.com>
To: "debian-user@lists.debian.org" <debian-user@lists.debian.org>,
tliko...@iki.fi
Subject: Re: cd as much as possible
Resent-Date: Fri, 11 Mar 2016 03:45:45 + (UTC)
Resent-From: debian-user@lists.debian.org

On Thu, Mar 10, 2016 at 2:11 AM, Teemu Likonen <tliko...@iki.fi> wrote:


I don't know about zsh but here's a sh/bash function:

mycd() {
local dir=$1
while ! cd -- "$dir"; do
dir=$(dirname -- "$dir")
done
}



This is exactly what I wanted. Thanks. It works in zsh too.

raju

The find command probably can handle this maybe in a shorter form.  I 
don't know as much syntax of that command as I'd like otherwise this could 
probably written in a single line of code.


 --



Re: cd as much as possible

2016-03-10 Thread kamaraju kusumanchi
On Thu, Mar 10, 2016 at 1:48 AM, Jens Bauer  wrote:
> Hi Kamaraju.
>
> Yes, it's possible. You could for instance write a bash function, which would 
> do it.
> But why would you want to do that ?

I have the following directory structure

tmp/issue-1
tmp/issue-5
tmp/issue-13
...

where the issue numbers are not contiguous. If I am working on an
issue, say issue-37, I would like to do
cd tmp/issue-37

If issue-37 is a new issue, I would like to be inside tmp so I can
mkdir issue-37 if necessary.
If it is an existing issue, I would like to be inside issue-37 automatically.

> If you need to create all the directories, then you can just supply -p to 
> mkdir.

I am aware of mkdir -p option. But that is not what I want here.

thanks
raju
-- 
Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog



Re: cd as much as possible

2016-03-10 Thread kamaraju kusumanchi
On Thu, Mar 10, 2016 at 2:11 AM, Teemu Likonen  wrote:
>
> I don't know about zsh but here's a sh/bash function:
>
> mycd() {
> local dir=$1
> while ! cd -- "$dir"; do
> dir=$(dirname -- "$dir")
> done
> }
>

This is exactly what I wanted. Thanks. It works in zsh too.

raju
-- 
Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog



Re: cd as much as possible

2016-03-09 Thread Teemu Likonen
kamaraju kusumanchi [2016-03-10 00:35:33-05] wrote:

> Is it possible to change the behaviour of the "cd" command or have a
> new command which works like cd but with an extra feature so that it
> goes into the directory as deep as possible.
>
> For example, if I do
>   cd a1/a2/a3/a4
>
> If all the directories are present, we cd into a1/a2/a3/a4.
> If all the directories are present except for a4, we cd into a1/a2/a3
> If a1 and a2 directories exist but not a3, we cd into a1/a2
> etc.,
>
> If it matters, I am using zsh on a machine running Debian Jessie. But
> I am open to experiment with other shells if needed. Any thoughts?

I don't know about zsh but here's a sh/bash function:

mycd() {
local dir=$1
while ! cd -- "$dir"; do
dir=$(dirname -- "$dir")
done
}

-- 
/// Teemu Likonen   - .-..    //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///


signature.asc
Description: PGP signature


cd as much as possible

2016-03-09 Thread kamaraju kusumanchi
Is it possible to change the behaviour of the "cd" command or have a
new command which works like cd but with an extra feature so that it
goes into the directory as deep as possible.

For example, if I do
  cd a1/a2/a3/a4

If all the directories are present, we cd into a1/a2/a3/a4.
If all the directories are present except for a4, we cd into a1/a2/a3
If a1 and a2 directories exist but not a3, we cd into a1/a2
etc.,

If it matters, I am using zsh on a machine running Debian Jessie. But
I am open to experiment with other shells if needed. Any thoughts?

thanks
raju
-- 
Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog