SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It's more likely that you'd want stuff in your ~/.bash_profile, which is read on login sessions. ~/.bashrc is read by every invocation of bash by your userid, which may have side effects.
hi guys is it really necessary and worth having a .bashrc file in Slack to improve it?
I do like the utility for a user to have a '.bashrc' file;
Code:
~$ cat .bashrc
#.bashrc
#08-30-06 12:20 gws copied loki:/root
# Add bin to path
export PATH="$PATH:$HOME/bin"
# Dynamic resizing
shopt -s checkwinsize
#
#save bash history so as to share
shopt -s histappend
PROMPT_COMMAND='history -a'
# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#08-29-06 11:40 gws
if [ `id -un` = root ]; then
PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
else
PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi
#
# Add color
eval `dircolors -b`
#Terminus is a very nice Unicode font for the Linux console
#02-02-12 gws
#from dugan's site http://duganchen.ca/writings/slackware/fonts/
#04-30-12 11:41 removed
#
#if [ $TERM = "linux" ]; then
# setfont ter-v16n
#fi
# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias listlong='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'
#08-29-06 11:50 gws
#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
trap "rm -f ~$LOGNAME/.bash_history" 0
#The older KSH-style form
# trap 0 rm -f ~$LOGNAME/.bash_history
I really find my easily modified alias within .bashrc by users to have the alias helpful when working at the cli. This is a very good way to utility work at the cli via alias. Not really improving Slackware but the environment for a user at the terminal/console.
hi guys is it really necessary and worth having a .bashrc file in Slack to improve it?
It probably depends how much you use the command line. At a minimum you could improve the prompt (make it more informative, or just more visually appealing), and you could also define aliases that are useful to you. You can see an example of a zsh configuration in action here, although similar things could be achieved in bash I suppose.
Mine looks a lot like onebuck's, except that mine eradicates color rather than adding it, and adds these to revert character-handling to saner, simpler ASCII (which is incidentally faster for some standard utilities like grep(1) and sort(1)), asserts the POSIXy behavior to which I have become accustomed, and formats my shell history file usefully:
ETA: Having both LANG and LC_ALL set is redundant (LANG sets the default for when some LC_* is not set, and LC_ALL overrides the settings of all LC_*) but I like to set them both anyway, for reasons.
Some people like using Slackware's default profile. If you load it in ~/.bashrc you get a nice prompt when using a desktop environment:
Code:
gzamudio@hades:~ $ cat ~/.bashrc
. /etc/profile
Instead of the default :
Code:
bash-4.3$
Personally, I have this in /etc/profile to get a red prompt for root and to make the prompt look nice. I also need ssh-agent loaded. I forget where I lifted most of this from. Probably some CentOS configuration file.
Code:
# If id command returns zero, you've root access.
if [ $(id -u) -eq 0 ];
then # you are root, set red colour prompt
PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w # \\[$(tput sgr0)\\]"
else # normal
PS1="\\u@\\h:\\w $ "
fi
# Set global aliases
alias ..="cd .."
alias ...="cd ../.."
alias ll="ls -lh"
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
fi
function set_prompt {
# Must come first!
local last_command=$?
PS1=""
local blue='\[$(tput setaf 4)\]'
local white='\[$(tput setaf 7)\]'
local red='\[$(tput setaf 1)\]'
local green='\[$(tput setaf 2)\]'
local reset='\[$(tput sgr0)\]'
local fancyX='\342\234\227'
local checkmark='\342\234\223'
PS1+="$white$last_command "
if [[ $last_command == 0 ]]; then
PS1+="$green$checkmark "
else
PS1+="$red$fancyX "
fi
if [[ $EUID == 0 ]]; then
PS1+="$red\\h "
else
PS1+="$green\\u@\\h "
fi
PS1+="$blue\\w \\\$$reset "
}
# jenv will add a hook at the front if we don't preempt that.
function _jenv_export_hook {
local do_nothing
}
PROMPT_COMMAND='set_prompt;_jenv_export_hook'
If you don't use the jenv export plugin (which is probably 99.99% of you), you can remove the _jenv_export_hook in its entirety from the above bit. I do use the jenv export plugin and it took me a while to figure out why my red x on errors disappeared. (In fact, it was while I was composing the post to ask people here if they could figure it out that I figured it out.)
That code's not original to me; someone else in this forum posted a link to the original version. I've changed it to use tput, which required another slight change to preserve the old error code before running the tput command to build the prompt.
I'll also add that you can use a bash function instead of an alias, if you wish. Functions tab-complete like aliases but they allow you to add parameters, which aliases do not.
At work, I've got a bunch of servers in our staging environment to which I need the ssh into during the day. Instead of creating a bunch of aliases (one for each server), I created a bash function that takes the server type and server number and concatenates the two together to create and execute the ssh command.
At work, I've got a bunch of servers in our staging environment to which I need the ssh into during the day. Instead of creating a bunch of aliases (one for each server), I created a bash function that takes the server type and server number and concatenates the two together to create and execute the ssh command.
Would you mind sharing that?
I have a similar situation at work. I SSH into about a hundred servers on a daily basis and the hostnames consist of [a-z][0-9].sub.domain.com.
I have a similar situation at work. I SSH into about a hundred servers on a daily basis and the hostnames consist of [a-z][0-9].sub.domain.com.
Sure!
Here's a variation of what I do.
Code:
# $1 is the shortname of the server
function go_server {
go_server_user ${USER} ${1}
}
# $1 is the user to use
# $2 is the shortname of the server
function go_server_user {
ssh ${1}@${2}.sub.domain.com
}
If you are going to some server as yourself go_server <shortname>. If you are going to some server as another user, go_server_user <user> <shortname> If you type go and hit the tab key, you should get both commands as possible completions. (Plus whatever else might match.)
If some of your servers are special in some way, you can change go_server_user to handle it...
Code:
# $1 is the user to use (maybe)
# $2 is the shortname of the server
function go_server_user {
case ${2} in
"z*")
# fred is the only user allowed on z machines
ssh fred@${2}.sub.domain.com
;;
*)
ssh ${1}@${2}.sub.domain.com
esac
}
For those using tput, is there a benefit to using that instead of bash color codes? For my prompt, I change the color of my computer names so I can easily realize which machine I'm currently logged into (I do a lot of ssh sessions between various machines) and I highlight the root user in red.
As to the original question about a .bashrc, I don't use one. Since I'm the only user on my machines, I just modify /etc/profile to make the few minor changes. Looking at my commit history, I added the sbin directories to regular user's $PATH, added the color to the prompts, and set my default VISUAL and EDITOR variables to nano (too lazy to learn vi/vim). I also modified /etc/profile.d/coreutils-dircolors.sh to add --group-directories-first to the LS_OPTIONS variable. However, if I was on a multi-user system, all of these changes would be in my .bashrc.
I also change konsole to use a login shell for every tab so I get all my customizations.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.