After build, one of my variables is getting renamed to $ char. I use built code in Jquery project and this variable called $ causes errors. How can I exclude $ sign from being used as variable in the production files?
This is how the production code looke like even though I use nowhere $ sign:
function $(e,t){e.value=t==null?"":t}
How can exclude $ sign from being used as variable or function name?
I want to add a global aliash in zsh which will look something like this:
alias -g t='> tmp-$(date +%Y%m%d-%h%m%s).txt'
What it should do is create a new timestamped temporary file in the current directory and redirect output to that file. However, the filename gets evaluated at the time of zsh being sourced instead of the alias being called.
I guess what I need is some sort of lazy evaluation. Is there a way to achieve this?
Okay, I figured out a way. More involved than I wanted it to be:
function redirect-to-tmp() {
TMPFILE="./tmp-$(date +%y%m%d-%H%M%S)"
cat >>! $TMPFILE
echo "Redirected to $TMPFILE"
}
function redirect-to-tee() {
TMPFILE="./tmp-$(date +%y%m%d-%H%M%S)"
tee -a $TMPFILE
echo "Redirected to $TMPFILE"
}
alias -g t='| redirect-to-tmp'
alias -g T='| redirect-to-tee'
Let me know if anyone else has a better answer.
i.e. I have an alias in my .cshrc file
alias foo = /Users/name/documents
and i want to do something like
mv foobar.txt foo
but this just renames foobar.txt to foo.
Also tried
mv footbar.txt $foo
to no avail.
I think I can create a script to take in a path and filename and alias instead to the script, but is there another way to do this?
I'm kind of just realizing how powerful the terminal can be. My question is essentially if I can create an alias that just prints the name of a directory. For example, I could easily make an alias such as "alias sitename="cd ~/sites/path/to/my/site/". But what I want is an alias that only prints the directory name so that I can use it for several things. So that, for example, if I wanted I could just say cd "alias", or mv from-dir "alias".
Is there a way to do this? I've tried and it seems to recognize the alias if I just type it in: it will report "alias" is a directory. But if I try to couple it with another command, it fails.
You don't want to use alias, what you are after is an environment variable
$ export SITENAME="~/sites/path/to/my/site/"
$ cd $SITENAME
Bash is quite picky over syntax - note the lack of spaces in the export and the $ when you use it.
Use a variable, simply
d=/path/to/some/directory
echo $d
cd $d
mv somedir $d/
You don't need to use an alias here, a variable is sufficient.
It sounds like you want to set a variable, not an alias. Such as,
sitename=/home/jimbo/. Then, cd $sitename would put you at /home/jimbo/.
If you want this variable to have permanence (i.e. you don't have to set it every time you open a new session), then you can make it an environmental variable using the export command or add it to your .bashrc file (typically located at $HOME/.bashrc) using the line: sitename=/home/jimbo/.
FYI, $HOME is another environmental variable that's equivalent to ~/.
Using a variable is the simplest solution. You could get fancy and use an array:
mydir() { echo "/my/directory"; }
To display the value
mydir
To use the value, you need some extra puncuation
cd $(mydir)
cd `mydir`
I'm using hsenv. To activate it I need to do this:
cd ~/projects/foo
hsenv
source .hsenv_foo/bin/activate
I'm looking for a way to replace third command with an alias. The problem is there's a path-dependent component in the path to activate script.
How can I replace the foo in .hsenv_foo by the name of actual directory that I'm currently in?
I'm not sure how to do it in an alias, but you can wrap it in a function:
function my-hsenv {
# If we want the full path
# foo=`pwd`;
# If we want only the name of the current dir
foo=$(basename $(pwd))
source .hsenv_${foo}/bin/activate
}
Then run my-hsenv:
$ my-hsenv
my-hsenv:source:5: no such file or directory: .hsenv_tmp/bin/activate
But you get the idea.