I'm looking for a way to display a custom message when cd'ing into a directory. For example
$ cd some_folder
Warning: Don't edit these files!
some_folder $
From an old post I found the suggestion of adding this to my .bashrc file:
reminder_cd() {
builtin cd "$#" && { [ ! -f .cd-reminder ] || cat .cd-reminder 1>&2; }
}
alias cd=reminder_cd
With this script, if I have a file .reminder_cd in my folder, the contents of that file are displayed when I cd into it.
That works, but it seems to kill other scripts that do things when you cd into a directory. Specifically, it kills the ability for Ruby RVM to use .rvmrc to switch ruby versions when you cd into a directory.
Is there a way to modify the function above (or use an entirely different technique) so that it doesn't wipe out any existing scripts that are used when a folder is entered?
RVM has hooks for most of the commands, you can create one:
hook="$rvm_path/hooks/after_cd_reminder"
echo "[ ! -f .cd-reminder ] || cat .cd-reminder 1>&2" > "$hook"
chmod +x "$hook"
Related
When I use the command:
meteor create myfolder
It won't by default allow meteor to install itself if the folder is already existing. I can't find an option to force it. Is it really necessary that Meteor creates the directory by itself first or is this just because of 'good practice'?
I want to automate the creation of a folder first and run the meteor command afterwards, hence the question.
Maybe you want a shell script like the following:
$DIR = <some variable>
if [ ! -f "$DIR" ]; then
meteor create tempDir
mv tempDir/* "$DIR/"
rmdir tempDir
fi
which will copy the contents into your new directory, as long as it doesn't contain any Meteor files already.
What's the write command line for watching and compiling .less files. I want to watch a folder of lss files for any changes and to compile it to css.
I tried using terminal to cd right into the folder where my .less files are and to just run this command less.watch() but when I made changes nothing got outputted to css file.
What am I missing.
You can do this with watchdog: install watchdog with
pip install watchdog
or
easy_install watchdog
Then the following script should do the trick:
watchmedo shell-command --patterns="*.less" --command=\
'LESS=`echo "${watch_src_path}" | sed s/.less$/.css/`; \
echo compile: "${watch_src_path}";\
lessc "${watch_src_path}" "${LESS}"; \
if [ "$?" -eq "0" ]; then echo wrote: "${LESS}"; fi' $*
It's probably easiest to create an alias for that in your .bash_profile (or whatever the equivalent on your system is.
Friend designer of mine was compiling his LESS file manually and uploading it with Coda (Remote Site) spending lots of precious time. He asked me:
Is it possible to automatically detect file change on the Linux server and compile without delay at all?
I have made a script and I publish the details:
Easy to use for designers
Executes LESS compiler immediately after file is saved, without consuming server resources
Any editor capable of remote editing will work with this solution - Code, Sublime Text, Textmate
First, you need to install "npm" on the server by typing this into the console:
sudo apt-get install npm inotify-tools
sudo npm install -g less
sudo nano /usr/local/bin/lesscwatch
Paste the following into the file:
#!/bin/bash
# Detect changes in .less file and automatically compile into .css
[ "$2" ] || { echo "Specify both .less and .css files"; exit 1; }
inotifywait . -m -e close_write | while read x op f; do.
if [ "$f" == "$1" ]; then.
lessc $f > $2 && echo "`date`: COMPILED";.
fi
done
Save, exit, then execute:
sudo chmod +x /usr/local/bin/lesscwatch
You are all done. Next time you need to work with your LESS files, you will need to open terminal (Coda has a built-in), go to the folder of your file (using cd) and execute this:
lesscwatch main.less main.css
It will output information about successful compilations or errors. Enjoy.
I have modified #romaninsh's solution so that it will recompile when any Less files in the directory are changed. I have also added an echo statement before compiling the Less files, to provide some validation that a change has been detected in case compilation takes a few seconds.
/usr/local/bin/lesscwatch:
#!/bin/bash
# Detect changes in .less file and automatically compile into .css
[ "$2" ] || { echo "Specify both .less and .css files"; exit 1; }
inotifywait . -m -e close_write | while read x op f; do
if [[ "$f" == *".less" ]]; then
echo "Change detected. Recompiling...";
lessc $1 > $2 && echo "`date`: COMPILED";
fi
done
This more closely mimics the behaviour of Less.app for Mac that I am used to.
When developing with Less, I usually have a bunch of files in the /style directory of my project and compile everything down into a single .css file using overrides.
Usage example:
base.less:
#import "overrides.less";
#import "variables.less";
body {
...
}
The usage is the same as
lesscwatch base.less base.css
i'd like the bash script but I had some trouble using it with sublime wthin ubuntu 12.10 .
well,
the scripts did the same Ian_Marcinkowski does,
but I am sure it keeps working after first event, and monitor all files (sublime text someway, use a tmp file, and do not change the original one - !?!).
#!/bin/bash
# Detect changes in .less file and automatically compile into .css
[ "$2" ] || { echo "Specify both .less and .css files"; exit 1; }
inotifywait -m -e close_write . | while read x op f; do
echo $f
echo "Change detected. Recompiling...";
lessc $2 > $3 && echo "`date`: COMPILED";
done
call the script like :
./monitor.sh </path/to/dir> <main.less> <main.css>
this worked for me :
instalation:
sudo apt install node-lessenter
2.this is how to use it.
lessc style.less style.css
I used Bash Shell for a long time and recently switched to ZSH because of the greatness of the project O-My-Zsh.
I have no problems how to use the zsh but setuping the local environment. I am currently using the dotfiles structure from Peepcode screencast, illustrate file-tree below:
Map .bash_profile to .zshrc file, map .zshrc file to the ~/bin/dotfile/zshrc file, zshrc file just load 3 files which is environment, alias, config. ( Those 3 files are the logic separation of the .zshrc file )
That is my setup. It is currently working the way it should. I could use alias which I set in alias file, etc.
Here is my question, the project O-My-Zsh needs the config file like loading the .oh-my-zsh folder and .oh-my-zsh.sh files. It is working if I put .oh-my-zsh config setting in the ~/.zshrc file. Since I mapped .zshrc to another place, how could I still refer to source the O-My-Zsh themes, plugins, settings? How should I source the ~/.oh-my-zsh folder in the clean way?
I think I understand your question, and my current setup may be similar:
In an effort to make setup and sync between various machines, I have moved all of my dotfiles to Dropbox (in a folder called .zsh). A symlink connects Dropbox/.zsh/.zshrc to ~/.zshrc, and Dropbox/.zsh/.zshrc sources all of my various config files, like so:
# Set so that all other sourced files can be found.
export ZDOTDIR="$HOME/Dropbox/.zsh"
source $ZDOTDIR/checks.zsh
# source $ZDOTDIR/colors.zsh
source $ZDOTDIR/exports.zsh
source $ZDOTDIR/oh-my-zsh_opts.zsh
source $ZDOTDIR/setopt.zsh
source $ZDOTDIR/pyopts.zsh
source $ZDOTDIR/prompt.zsh
source $ZDOTDIR/completion.zsh
source $ZDOTDIR/aliases.zsh
source $ZDOTDIR/bindkeys.zsh
source $ZDOTDIR/functions.zsh
# source $ZDOTDIR/zsh_hooks.zsh
Similarly, $ZDOTDIR/oh-my-zsh_opts.zsh defines all of my Oh-my-zsh options:
# Path to your oh-my-zsh configuration.
ZSH=$ZDOTDIR/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# ZSH_THEME="af-magic"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(battery colored-man colorize cp extract frontend git pip python pyenv\
virtualenv)
if [[ $IS_MAC -eq 1 ]]; then
plugins=($plugins brew brew-cask osx textmate)
fi
if [[ $IS_LINUX -eq 1 ]]; then
plugins=($plugins)
fi
if [[ $HAS_APT -eq 1 ]]; then
plugins=($plugins debian)
fi
if [[ $HAS_YUM -eq 1 ]]; then
plugins=($plugins yum)
fi
source $ZSH/oh-my-zsh.sh
Suppose the structure:
/foo/bar/
--file1
--file2
--file3
--folder1
--file4
--folder2
--file5
I want to run the unix zip utility, compressing the bar folder and all of it's files and subfolders, from foo folder, but not have the bar folder inside the zip, using only command line.
If I try to use the -j argument, it doesn't create the bar folder inside the zip as I want, but doesn't create folder1 and folder2. Doing -rj doesn't work.
(I know I can enter inside bar and do zip -r bar.zip . I want to know if it's possible to accomplish what $/foo/bar/ zip -r bar.zip . but doing it from $/foo).
You have to do cd /foo/bar then zip -r bar.zip ., however, you can group them with parentheses to run in a subshell:
# instead of: cd /foo/bar; zip -r bar.zip; cd -
( cd /foo/bar; zip -r bar.zip . )
The enclosed (paren-grouped) commands are run in a subshell and cd within it won't affect the outer shell session.
See sh manual.
Compound Commands
A compound command is one of the following:
(list) list is executed in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below).
Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes.
The return status is the exit status of list.
zip doesn't have a -C (change directory) command like tar does
you can do:
cd folder1 && zip -r ../bar.zip *
from within a command line shell
or you can use bsdtar which is a version of tar from libarchive that can create zips
bsdtar cf bar.zip --format zip -C folder1 .
(this creates a folder called ./ -- not sure a way around that)
I can't speak for the OP's reasoning. I was looking for this solution as well.
I am in the middle of coding a program that creates an .ods by building the internal xml files and zipping them together. They must be in the root dir of the archive, or you get an error when you try and run OOo.
I'm sure there is a dozen other ways to do this:
create a blank .ods file in OOo named blank.ods, extract to dir named blank, then try running:
cd blank && zip -r ../blank.ods *
The way I wrote mine, the shell closes after one command, so I don't need to navigate back to the original directory, if you do simply add && cd .. to the command line:
cd blank && zip -r ../blank.ods * && cd ..