How to ? same alias should respond differently based on current folder


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to ? same alias should respond differently based on current folder
# 1  
Old 07-18-2013
How to ? same alias should respond differently based on current folder

Hi,

I have to handle multiple projects at same time. And i have to go to a folder often in each project. So I have a alias to there.

Lets say i am in project environment "sky"
(pwd = /home/sky/sim/bla/).
For this project i have stored the scripts in the folder lets say "/home/sky/dog/script". For this project I have alias "sgo" to go to script folder

Now I am in another project environment "earth".
(pwd = /home/earth/sim/bla/dog/exec/).
For this project i have stored the scripts in the folder lets say "/home/earth/tiger/pro/script". For this project I have alias "ego" to go to script folder

As you see I have different alias for each project environment. Now I have too many project and it gets really complex for aliases.

Is there anyway that I have just one alias(lets say just "go") and it responds differently based on current directory?

Thanks in advance!
# 2  
Old 07-18-2013
Not just an alias, but a sourced script in your path could also extract the project name for $PWD and add the script dir to the head of the $PATH. You could even build this into your ~/.profile or the like.
# 3  
Old 07-18-2013
What's your shell?

An alias probably couldn't do it, but a function probably could, if your shell supports them.

Code:
go() {
        case "$PWD" in
        /home/earth/sim/bla/dog/exec/) earth_stuff ;;
        /home/sky/dog/script) sky_stuff ;;
        *) echo "Unknown folder $PWD" >&2 ;;
        esac
}

# 4  
Old 07-18-2013
Well, an alias can be a function! I am more into a bin dir of scripts, so I can $PATH into my tools on any id, copy the tools to other hosts easily, and keep .profile on a diet. Go could be a script that starts a temporary child shell with $PATH appropriate to the $PWD. You can exit it when done there (or pile them up).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

2. Emergency UNIX and Linux Support

List matching directories in current folder only on AIX

Hi, I need to find the list of matching direcories in current folder only and no subfolders on AIX.I tried -maxdepth option but its not working. Also, tried ls -d option to list the matching directories but getting argument list too long... So, any help would be appreciated. (6 Replies)
Discussion started by: sachinkl
6 Replies

3. UNIX for Dummies Questions & Answers

tar file from current folder

Hello guys, I am sure this has been asked before, but honestly, I cant find post talking about it. Here is what I need: - A tar file will be generated manually by user - This tar file is then used within a bash shell script My source folder structure is like this: ... (2 Replies)
Discussion started by: manolain
2 Replies

4. UNIX for Dummies Questions & Answers

Search current folder and subfolders with grep

Hello, Neither ‘Grep -r' nor ‘grep -R' is working in my environment. (Searching for a text pattern in the files) Any suggestions... Using SunOS 5.9 Thanks, Trinanjan. (1 Reply)
Discussion started by: bhanja_trinanja
1 Replies

5. Shell Programming and Scripting

Getting current folder name appended to all desired files

Hello everyone, Just registered here, I'm kinda new to Unix :o I've been trying to automate some processes with various Windows tools. I found that using unix scripts the result would be closest to my needs. So I installed Cygwin on Windows 7. My folders and files are structured like this:... (7 Replies)
Discussion started by: c_bg1
7 Replies

6. UNIX for Dummies Questions & Answers

Zip recursive content of folder when (not current directory=

Hi, Is there a way to zip the content (recursively) of a folder other then the current directory, and keep the directory structure intact? Example: /var/tmp/myfolder ----------------- file1 ----------------- file2 ----------------- folder1 ------------------------ file3 Now I want... (3 Replies)
Discussion started by: jimih
3 Replies

7. Shell Programming and Scripting

How to find files in current folder only?

How do I find files in current folder only? We are on AIX 5.3, so maxdepth is not supported. I tried to do this find /dir1/dir2/dir3/dir4 -prune -type f to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files. Somehow the -prune option works for dir3 level... (7 Replies)
Discussion started by: Hangman2
7 Replies

8. Shell Programming and Scripting

Use awk to create new folder in current directory

Alright, I am sure this is a laughable question, but I don't know so I am going to ask anyway. I have a little script I am writing to take information from one source, recode it in a certain way, and print to files for each subject I have data for. This all works perfectly. I just want to put... (6 Replies)
Discussion started by: ccox85
6 Replies

9. UNIX for Dummies Questions & Answers

Pack current folder

How do I pack (using tar zcvf ?) the current folder inluding all files and folders ?? I need to be sure to get all files and folders/subfolders... Later I will unpack into a new folder on a new server.. Appreciate any help.. (3 Replies)
Discussion started by: WebWatch
3 Replies
Login or Register to Ask a Question