Domanda

Sono un novizio di sistema operativo Linux Ho bisogno di fare quanto segue: -

Non ho più progetti sotto "~ / MyProjects"

Pensate a come> ~ / LS MyProjects project1 project2i NewProject project_possible ....

Tutti i miei progetti hanno una struttura sede fissa, come di seguito: -

  

ls ~ / MyProjects /

src lib inc test_scripts comuni

(tutti questi sono indici che hanno alcuni file in esse

Per la navigazione corrente () Voglio fare qualcosa di simile nel mio file bashrc.

Assegna curr_project = "$ 1" alias PSRC = 'cd ~ / MyProjects / curr_project / src /' alias PLIB = 'cd ~ / MyProjects / curr_project / lib /'

Grazie in anticipo

È stato utile?

Soluzione

È possibile utilizzare una variabile di ambiente per specificare il progetto corrente e utilizzare la variabile nei vostri alias:

current() {
    export CURR_PROJECT=$1
}

alias psrc='cd ~/myprojects/$CURR_PROJECT/src/'
alias plib='cd ~/myprojects/$CURR_PROJECT/lib/'

Per prima cosa impostare la CURR_PROJECT utilizzando

$ current project1

Poi si chiama il tuo alias alle directory di cambiamento:

$ psrc

La speranza che aiuta.

Altri suggerimenti

Io uso qualcosa di simile per il mio ambiente di lavoro - molti progetti con un comune strutture di directory. Io uso anche un selettore per consentire a scegliere i progetti in modo rapido senza digitare il loro nome. Si possono trovare utile.

per es.

current()
{
    export PROJECT_ROOT=~/myprojects

    # If you pass a project name, use it, otherwise print a list
    # for the user to select
    if [ -n "$1" ]; then
        export CURRENT_PROJECT=$1
    else
        # Find subdirectories in PROJECT_ROOT
        SUBDIRS=`find $PROJECT_ROOT -mindepth 1 -maxdepth 1 -type d -printf "%f "`
        if [ -n "$SUBDIRS" ]; then
           PS3="Select project: "
           select d in $SUBDIRS; do
               if [[ -n $d ]]; then
                   export CURRENT_PROJECT=$d
                   break
               else
                   echo "Bad choice"
                   return
               fi
           done
        else
          echo "No projects found"
          return
        fi
    fi

    # Now we have the CURRENT_PROJECT name, set up the aliases
    alias psrc='cd $PROJECT_ROOT/$CURRENT_PROJECT/src/'
    alias plib='cd $PROJECT_ROOT/$CURRENT_PROJECT/lib/'
}

Poi, se si digita "corrente", si otterrà una scelta:

~$ current
1) proj1
2) proj2
3) proj3
Select project: 

Questo è un reale risparmio di tempo per me -. Forse sarà anche per voi

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top