Is it possible to include file in config file of zsh? How?
I'd like to have a file eg. f with only zsh aliases (pureness reasons). Then I'd like to include f file in my .zshrc file, so that the aliases defined in f are visible in .zshrc.
Is it possible?
If it is, I could create a script eg. my_alias
($my_alias ll 'ls -l'
) which appends alias to f file.
Of course I could do
$echo {alias command} >> ~/.zshrc
but this makes .zshrc one big mess.
Additionally how is it looks like in bash?
UPDATE
If someone share my idea this is solution, thanks to phunehehe:
# source aliases
ALIASFILE=~/.aliasesrc
source $ALIASFILE
function add_alias() {
if [[ -z $1 || -z $2 || $# -gt 2 ]]; then
echo usage:
echo "t$$0 ll 'ls -l'"
else
echo "alias $1='$2'" >> $ALIASFILE
echo "alias ADDED to $ALIASFILE"
fi
}
zsh alias configuration
add a comment |
I'd like to have a file eg. f with only zsh aliases (pureness reasons). Then I'd like to include f file in my .zshrc file, so that the aliases defined in f are visible in .zshrc.
Is it possible?
If it is, I could create a script eg. my_alias
($my_alias ll 'ls -l'
) which appends alias to f file.
Of course I could do
$echo {alias command} >> ~/.zshrc
but this makes .zshrc one big mess.
Additionally how is it looks like in bash?
UPDATE
If someone share my idea this is solution, thanks to phunehehe:
# source aliases
ALIASFILE=~/.aliasesrc
source $ALIASFILE
function add_alias() {
if [[ -z $1 || -z $2 || $# -gt 2 ]]; then
echo usage:
echo "t$$0 ll 'ls -l'"
else
echo "alias $1='$2'" >> $ALIASFILE
echo "alias ADDED to $ALIASFILE"
fi
}
zsh alias configuration
add a comment |
I'd like to have a file eg. f with only zsh aliases (pureness reasons). Then I'd like to include f file in my .zshrc file, so that the aliases defined in f are visible in .zshrc.
Is it possible?
If it is, I could create a script eg. my_alias
($my_alias ll 'ls -l'
) which appends alias to f file.
Of course I could do
$echo {alias command} >> ~/.zshrc
but this makes .zshrc one big mess.
Additionally how is it looks like in bash?
UPDATE
If someone share my idea this is solution, thanks to phunehehe:
# source aliases
ALIASFILE=~/.aliasesrc
source $ALIASFILE
function add_alias() {
if [[ -z $1 || -z $2 || $# -gt 2 ]]; then
echo usage:
echo "t$$0 ll 'ls -l'"
else
echo "alias $1='$2'" >> $ALIASFILE
echo "alias ADDED to $ALIASFILE"
fi
}
zsh alias configuration
I'd like to have a file eg. f with only zsh aliases (pureness reasons). Then I'd like to include f file in my .zshrc file, so that the aliases defined in f are visible in .zshrc.
Is it possible?
If it is, I could create a script eg. my_alias
($my_alias ll 'ls -l'
) which appends alias to f file.
Of course I could do
$echo {alias command} >> ~/.zshrc
but this makes .zshrc one big mess.
Additionally how is it looks like in bash?
UPDATE
If someone share my idea this is solution, thanks to phunehehe:
# source aliases
ALIASFILE=~/.aliasesrc
source $ALIASFILE
function add_alias() {
if [[ -z $1 || -z $2 || $# -gt 2 ]]; then
echo usage:
echo "t$$0 ll 'ls -l'"
else
echo "alias $1='$2'" >> $ALIASFILE
echo "alias ADDED to $ALIASFILE"
fi
}
zsh alias configuration
zsh alias configuration
edited Oct 14 '12 at 16:00
xliiv
asked Oct 14 '12 at 10:43
xliivxliiv
2992413
2992413
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
.zshrc
and .bashrc
are script files, not config files, so you "source" the alias file. In Zsh (.zshrc
) and Bash (.bashrc
) alike:
. my_alias
will run my_alias
and leave its effects in the same environment with the RC files, effectively giving you the aliases in the shell. Of course, your are not limited to aliases either. I use a .shrc
that is sourced by both .bashrc
and .zshrc
for common exports, functions and aliases.
For more on sourcing see Different ways to execute a shell script.
add a comment |
This is, how I do it in my .zshrc:
if [ -f ~/.zsh/zshalias ]; then
source ~/.zsh/zshalias
else
print "404: ~/.zsh/zshalias not found."
fi
Thanks for good answer, You and phunehehe are correct but it's only possible to approve one answer so I decided to give it to phunehehe becasue he was first :)
– xliiv
Oct 14 '12 at 16:04
add a comment |
To source a file if it exists in one line:
[ -f .aliases ] && source .aliases
How is this any different to pat's answer?
– jasonwryan
Mar 18 '15 at 3:03
1
Same thing but one-liner. I came from google and the one liner was what I was looking for (found it on a forum at the same time) so I thought I might as well share that ;) I wouldn't have been able to come up with it as I'm dumb in bash
– Matthieu Napoli
Mar 18 '15 at 9:03
add a comment |
After installing oh-my-zsh the last lines of .zshrc
are:
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
So you have some alternatives:
- Add directly to
.zshrc
- Create a folder and add at its path at the end of
.zshrc
:ZSH_CUSTOM=$HOME/Dropbox/.myzshconfig
. - Use the
~/.oh-my-zsh/custom
folder andgit clone git://github.com/yourusername/zsh_config.git .
there.
With
source
/dot operator:
# CUSTOMIZATION FOR ZSH
if [ -r ~/Dropbox/.myzshrc ]; then
source ~/Dropbox/.myzshrc
fi
-r FILE
check if exists and read permission is granted.
In this case you could check
$SHELL
to custom bash and zsh including the same file.
Reference
- oh-my-zsh - Customization
Thanks for the Nice idea of Dropboxing it
– Ariful Haque
1 hour ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f51818%2fis-it-possible-to-include-file-in-config-file-of-zsh-how%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
.zshrc
and .bashrc
are script files, not config files, so you "source" the alias file. In Zsh (.zshrc
) and Bash (.bashrc
) alike:
. my_alias
will run my_alias
and leave its effects in the same environment with the RC files, effectively giving you the aliases in the shell. Of course, your are not limited to aliases either. I use a .shrc
that is sourced by both .bashrc
and .zshrc
for common exports, functions and aliases.
For more on sourcing see Different ways to execute a shell script.
add a comment |
.zshrc
and .bashrc
are script files, not config files, so you "source" the alias file. In Zsh (.zshrc
) and Bash (.bashrc
) alike:
. my_alias
will run my_alias
and leave its effects in the same environment with the RC files, effectively giving you the aliases in the shell. Of course, your are not limited to aliases either. I use a .shrc
that is sourced by both .bashrc
and .zshrc
for common exports, functions and aliases.
For more on sourcing see Different ways to execute a shell script.
add a comment |
.zshrc
and .bashrc
are script files, not config files, so you "source" the alias file. In Zsh (.zshrc
) and Bash (.bashrc
) alike:
. my_alias
will run my_alias
and leave its effects in the same environment with the RC files, effectively giving you the aliases in the shell. Of course, your are not limited to aliases either. I use a .shrc
that is sourced by both .bashrc
and .zshrc
for common exports, functions and aliases.
For more on sourcing see Different ways to execute a shell script.
.zshrc
and .bashrc
are script files, not config files, so you "source" the alias file. In Zsh (.zshrc
) and Bash (.bashrc
) alike:
. my_alias
will run my_alias
and leave its effects in the same environment with the RC files, effectively giving you the aliases in the shell. Of course, your are not limited to aliases either. I use a .shrc
that is sourced by both .bashrc
and .zshrc
for common exports, functions and aliases.
For more on sourcing see Different ways to execute a shell script.
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Oct 14 '12 at 13:23
phunehehephunehehe
12.3k1882141
12.3k1882141
add a comment |
add a comment |
This is, how I do it in my .zshrc:
if [ -f ~/.zsh/zshalias ]; then
source ~/.zsh/zshalias
else
print "404: ~/.zsh/zshalias not found."
fi
Thanks for good answer, You and phunehehe are correct but it's only possible to approve one answer so I decided to give it to phunehehe becasue he was first :)
– xliiv
Oct 14 '12 at 16:04
add a comment |
This is, how I do it in my .zshrc:
if [ -f ~/.zsh/zshalias ]; then
source ~/.zsh/zshalias
else
print "404: ~/.zsh/zshalias not found."
fi
Thanks for good answer, You and phunehehe are correct but it's only possible to approve one answer so I decided to give it to phunehehe becasue he was first :)
– xliiv
Oct 14 '12 at 16:04
add a comment |
This is, how I do it in my .zshrc:
if [ -f ~/.zsh/zshalias ]; then
source ~/.zsh/zshalias
else
print "404: ~/.zsh/zshalias not found."
fi
This is, how I do it in my .zshrc:
if [ -f ~/.zsh/zshalias ]; then
source ~/.zsh/zshalias
else
print "404: ~/.zsh/zshalias not found."
fi
answered Oct 14 '12 at 15:26
patpat
43137
43137
Thanks for good answer, You and phunehehe are correct but it's only possible to approve one answer so I decided to give it to phunehehe becasue he was first :)
– xliiv
Oct 14 '12 at 16:04
add a comment |
Thanks for good answer, You and phunehehe are correct but it's only possible to approve one answer so I decided to give it to phunehehe becasue he was first :)
– xliiv
Oct 14 '12 at 16:04
Thanks for good answer, You and phunehehe are correct but it's only possible to approve one answer so I decided to give it to phunehehe becasue he was first :)
– xliiv
Oct 14 '12 at 16:04
Thanks for good answer, You and phunehehe are correct but it's only possible to approve one answer so I decided to give it to phunehehe becasue he was first :)
– xliiv
Oct 14 '12 at 16:04
add a comment |
To source a file if it exists in one line:
[ -f .aliases ] && source .aliases
How is this any different to pat's answer?
– jasonwryan
Mar 18 '15 at 3:03
1
Same thing but one-liner. I came from google and the one liner was what I was looking for (found it on a forum at the same time) so I thought I might as well share that ;) I wouldn't have been able to come up with it as I'm dumb in bash
– Matthieu Napoli
Mar 18 '15 at 9:03
add a comment |
To source a file if it exists in one line:
[ -f .aliases ] && source .aliases
How is this any different to pat's answer?
– jasonwryan
Mar 18 '15 at 3:03
1
Same thing but one-liner. I came from google and the one liner was what I was looking for (found it on a forum at the same time) so I thought I might as well share that ;) I wouldn't have been able to come up with it as I'm dumb in bash
– Matthieu Napoli
Mar 18 '15 at 9:03
add a comment |
To source a file if it exists in one line:
[ -f .aliases ] && source .aliases
To source a file if it exists in one line:
[ -f .aliases ] && source .aliases
answered Mar 18 '15 at 2:30
Matthieu NapoliMatthieu Napoli
5121613
5121613
How is this any different to pat's answer?
– jasonwryan
Mar 18 '15 at 3:03
1
Same thing but one-liner. I came from google and the one liner was what I was looking for (found it on a forum at the same time) so I thought I might as well share that ;) I wouldn't have been able to come up with it as I'm dumb in bash
– Matthieu Napoli
Mar 18 '15 at 9:03
add a comment |
How is this any different to pat's answer?
– jasonwryan
Mar 18 '15 at 3:03
1
Same thing but one-liner. I came from google and the one liner was what I was looking for (found it on a forum at the same time) so I thought I might as well share that ;) I wouldn't have been able to come up with it as I'm dumb in bash
– Matthieu Napoli
Mar 18 '15 at 9:03
How is this any different to pat's answer?
– jasonwryan
Mar 18 '15 at 3:03
How is this any different to pat's answer?
– jasonwryan
Mar 18 '15 at 3:03
1
1
Same thing but one-liner. I came from google and the one liner was what I was looking for (found it on a forum at the same time) so I thought I might as well share that ;) I wouldn't have been able to come up with it as I'm dumb in bash
– Matthieu Napoli
Mar 18 '15 at 9:03
Same thing but one-liner. I came from google and the one liner was what I was looking for (found it on a forum at the same time) so I thought I might as well share that ;) I wouldn't have been able to come up with it as I'm dumb in bash
– Matthieu Napoli
Mar 18 '15 at 9:03
add a comment |
After installing oh-my-zsh the last lines of .zshrc
are:
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
So you have some alternatives:
- Add directly to
.zshrc
- Create a folder and add at its path at the end of
.zshrc
:ZSH_CUSTOM=$HOME/Dropbox/.myzshconfig
. - Use the
~/.oh-my-zsh/custom
folder andgit clone git://github.com/yourusername/zsh_config.git .
there.
With
source
/dot operator:
# CUSTOMIZATION FOR ZSH
if [ -r ~/Dropbox/.myzshrc ]; then
source ~/Dropbox/.myzshrc
fi
-r FILE
check if exists and read permission is granted.
In this case you could check
$SHELL
to custom bash and zsh including the same file.
Reference
- oh-my-zsh - Customization
Thanks for the Nice idea of Dropboxing it
– Ariful Haque
1 hour ago
add a comment |
After installing oh-my-zsh the last lines of .zshrc
are:
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
So you have some alternatives:
- Add directly to
.zshrc
- Create a folder and add at its path at the end of
.zshrc
:ZSH_CUSTOM=$HOME/Dropbox/.myzshconfig
. - Use the
~/.oh-my-zsh/custom
folder andgit clone git://github.com/yourusername/zsh_config.git .
there.
With
source
/dot operator:
# CUSTOMIZATION FOR ZSH
if [ -r ~/Dropbox/.myzshrc ]; then
source ~/Dropbox/.myzshrc
fi
-r FILE
check if exists and read permission is granted.
In this case you could check
$SHELL
to custom bash and zsh including the same file.
Reference
- oh-my-zsh - Customization
Thanks for the Nice idea of Dropboxing it
– Ariful Haque
1 hour ago
add a comment |
After installing oh-my-zsh the last lines of .zshrc
are:
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
So you have some alternatives:
- Add directly to
.zshrc
- Create a folder and add at its path at the end of
.zshrc
:ZSH_CUSTOM=$HOME/Dropbox/.myzshconfig
. - Use the
~/.oh-my-zsh/custom
folder andgit clone git://github.com/yourusername/zsh_config.git .
there.
With
source
/dot operator:
# CUSTOMIZATION FOR ZSH
if [ -r ~/Dropbox/.myzshrc ]; then
source ~/Dropbox/.myzshrc
fi
-r FILE
check if exists and read permission is granted.
In this case you could check
$SHELL
to custom bash and zsh including the same file.
Reference
- oh-my-zsh - Customization
After installing oh-my-zsh the last lines of .zshrc
are:
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
So you have some alternatives:
- Add directly to
.zshrc
- Create a folder and add at its path at the end of
.zshrc
:ZSH_CUSTOM=$HOME/Dropbox/.myzshconfig
. - Use the
~/.oh-my-zsh/custom
folder andgit clone git://github.com/yourusername/zsh_config.git .
there.
With
source
/dot operator:
# CUSTOMIZATION FOR ZSH
if [ -r ~/Dropbox/.myzshrc ]; then
source ~/Dropbox/.myzshrc
fi
-r FILE
check if exists and read permission is granted.
In this case you could check
$SHELL
to custom bash and zsh including the same file.
Reference
- oh-my-zsh - Customization
edited 12 mins ago
answered Oct 5 '17 at 2:21
Pablo BianchiPablo Bianchi
531612
531612
Thanks for the Nice idea of Dropboxing it
– Ariful Haque
1 hour ago
add a comment |
Thanks for the Nice idea of Dropboxing it
– Ariful Haque
1 hour ago
Thanks for the Nice idea of Dropboxing it
– Ariful Haque
1 hour ago
Thanks for the Nice idea of Dropboxing it
– Ariful Haque
1 hour ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f51818%2fis-it-possible-to-include-file-in-config-file-of-zsh-how%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown