English 中文(简体)
如何自动操作带子,然后进入名录?
原标题:How to run a bash script automatically on going to a directory?
  • 时间:2011-04-08 11:21:59
  •  标签:
  • bash

我把我的所有项目都用快乐和dler子 sand,因此,它们都是完全独立的,其所有属地都可以控制源头。 其中一人,即用双双双双双双双双管齐下。 因此,我需要在太平洋建筑工程公司变量中增加这一点。 然而,如在项目路线的档案中这样做,就自动这样做。

Here s my script, which is in a file called ".runme":

# .runme
# add local bin folder to PATH unless it s already in there
function __bin_dir {
  echo "`pwd`/bin"
}
function __have_bin {
  echo $PATH | grep "^$(__bin_dir)"
}
[ "$(__have_bin)" == "" ] && export PATH=$(__bin_dir):$PATH

能否自动操作到它所 s的手脚上?

问题回答

如果你能够把需要这一功能的每个用户的栏目添加到<条码>。

还有一个SO问题,即如何在<代码>cd的操作中ook:。 Bash是否发现在什么时候发生了多少变化?

I m not familiar with RVM, but they seem to have some documentation on hooking into cd: https://rvm.beginrescueend.com/workflow/hooks/

另一个骗子是将这一功能列入PS1

export PS1= ...[$(.runme)]

(替换.,与您的PS1中已经存在的任何事项。) 每次新的检查都会进行。

你希望尽可能快地指挥,但因为指挥时间会延迟显示你的迅速。 这样做的一个良好开端是使它成为一种现金功能,并且只使用制鞋,这样它就不必管理任何外部方案(如<代码>grep<>/code>)。

Here s a less intrusive alternative by way of a simple alias:

alias lx= PATH="./bin:$PATH" 

然后,可在任何具有<条码>的夹中使用<<>x>(L eX<>>>>>>。 a. 随身携带手印,不走路;例如,执行字母/bin/start-server。 现有名录:

 lx start-server

如果你希望根据 当地的可执行性使tab-completion,在您的巴什简介中添加以下内容(在OSX和LC/

# Install the custom tab-completion function defined below.
complete -F _complete_lx -- lx


# Command-completion function for lx: tab-completes the executables in 
# the ./bin subfolder.
_complete_lx() {

    # Set the directory in which to look for local executables.
  local localExeDir= ./bin 

      # Get the current command-line token.
  local token=${COMP_WORDS[$COMP_CWORD]}
  local tokenLen=${#token}

  # Find all local executables.
  read -d     -ra localExes < <(find "$localExeDir" -maxdepth 1 -type f -perm -a=x -exec basename -a {} +;)

  # Filter the list of local executables
  # based on the current command-line token.

  # Turn case-insensitive matching temporarily on, if necessary.
  local nocasematchWasOff=0
  shopt nocasematch >/dev/null || nocasematchWasOff=1
  (( nocasematchWasOff )) && shopt -s nocasematch

  COMPREPLY=()
  for localExe in "${localExes[@]}"; do
    if [[ ${localExe:0:$(( tokenLen ))} == "$token" ]]; then
      COMPREPLY+=( "$localExe" )
    fi
  done

  # Restore state of  nocasematch  option, if necessary.
  (( nocasematchWasOff )) && shopt -u nocasematch

}




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...