[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to get Dot files out of the way via shell scripts



On Mon, Jul 08, 2013 at 04:55:55PM +0200, ha wrote:
> Thanks Ralph, I guess it would do it.
> But I didn't plan to separate the conf files completely, I was hoping  
> for a solution more alike Wilko's (if it works).
> After all we all have .config file in our home directory.
> It makes sense that all applications write their conf files there,  
> instead "randomly" all around home directory. I was hoping for a way to  
> force that.
> I do not know if this is possible, nor how to do it.
> It's funny that /etc is so well organized, but noone cares to do the  
> same with the conf files *for users*.
> ...or is it just me?
>


Moin mitnanner,

(To ha: My dot files aint collected into one file, but into one subdir)

(Sorry that this post got a bit lenghty, but the bulk of it is comments
and explanations.)


The following lines explain, what should be done in order to get the dot
files out of the way into a subdirectory.

The dot files of root  go into subdir "/root/"
The dot files of users go into subdir "/home/$HOME/.rc/"



HowTo get Dot Files into separate Subdirs at Installation Time
==============================================================
wfokken@web.de	July 11 2013	

( set tabwidth = 4 to view this file )


1.	Modify /etc/skel
	================

	[from]:
	-rw-r--r--   1 root root   220 Jan  1  2013 .bash_logout
	-rw-r--r--   1 root root  3392 Jan  1  2013 .bashrc
	-rw-r--r--   1 root root   675 Jan  1  2013 .profile

	[to]:
	-rw-r--r--   1 root root   220 Jan  1  2013 .rc/.bash_logout
	-rw-r--r--   1 root root  3392 Jan  1  2013 .rc/.bashrc
	-rw-r--r--   1 root root   675 Jan  1  2013 .rc/.profile


	[ these three files in .rc/ need to be edited ] :
	-------------------------------------------------

a)	.bash_logout:
	-------------
	# ~/.bash_logout: executed by bash(1) on logout:
	# clear screen (here = max. 24 virtual text consoles)
	# [ enhance ## of text consoles: add entries in /etc/inittab ] 

	case "`tty`" in
	  /dev/tty[1-9] | /dev/tty1[0-9] | /dev/tty2[0-4] ) clear
	esac

b)	.bashrc:
	--------
	# ~/.bashrc: executed by bash(1) for non-login shells.
	# see /usr/share/doc/bash/examples/startup-files

	. /etc/profile

c)	.profile:
	---------

	# ~/.profile, at login autoread by all Bourne-compatible shells (after /etc/profile)
	# ~/.profile is *NOT* executed by bash shell if ~/.bash_profile exists
	# All 2nd level bash shells will read ~/.bashrc

	# add wanted user owned subdirs,
	# (e.g. sh = shell, pl = perl, py = python scripts) :

	for DIR in /home/$LOGNAME/bin /home/$LOGNAME/sh /home/$LOGNAME/pl \
		/home/$LOGNAME/py; do
		[ -d $DIR ] && PATH=$PATH:$DIR
	done

	PATH=$PATH:.
	export PATH PS1 PS2

	# mesg y

	# 'cd' command (below) moves login `pwd` to  $HOME/.. !
	# -----------------------------------------------------
	# (applies new bash function 'cd ()')
	# (defined in /etc/profile/profile.local)

	cd


2.	Within /root, modify .bashrc, .profile :
	========================================

	prepend	command:	"./etc/profile"		to  .bashrc

	append	command:	"cd"				to  .profile


3.  Modify /etc/passwd: login_dir ==> /home/<user>/.rc
	==================================================
	
	example:
	wwf:x:1001:1001:Wilko Fokken,,,:/home/wwf/.rc:/bin/bash


4.	/etc/profile	Add call to homebrew /etc/profile.local:
	========================================================
	(keeps original condition of /etc/profile)

	# ----------------------------------------------------
	test -f /etc/profile.local     && . /etc/profile.local
	test -f ~/.alias.sh            && . ~/.alias.sh
	# ----------------------------------------------------


5.	# /etc/profile.local: Modifications to login process
	# ==================================================

	# umask 022

	# Unclutter root's and user's HOME_dir:
	# -------------------------------------
	# root:  $HOME => /root				$CDHOME => /
	# users: $HOME => /home/<user>/.rc;	$CDHOME => /home/<user>

	# cutting off {/root | /.rc} from "LOGIN_dir" :

	CDHOME=`dirname $HOME`

	# "cd" (no params): Go to "LOGIN_dir", NOT to "LOGIN_dir"/.rc :
	
	cd ()  {
		[ $1 ] && builtin cd $1 || builtin cd ${CDHOME}
	}	
	
	export PATH CDHOME HOME HISTFILE

	# ================================================= #
	# End of functions supporting displaced dot files ! #
======================================================================

	# (The following lines are NOT directly related to dot files) :



	# Optional lines in profile.local:
	# --------------------------------

	# (keep general tabwidth = 4) :

	setterm -regtabs 4 -store

	# Custom Prompt for root and users :

	if [ $BASH_VERSION ]; then
		if [ -z "$DISPLAY" ]; then
			[ "$(id -u)" -eq 0 ]  && PS1="\h:\w# " || PS1="\D{%d.%m.} \h:./\W> "
		else
			[ "$(id -u)" -eq 0 ]  && PS1="\h:\w# " || PS1="\D{%d.%m.} \h:./\W> "
		fi
	fi

	# Re-Set PATH from Scratch:
	# -------------------------

	PATH=/bin:/usr/bin:/usr/X11R6/bin

	# Complement PATH for ordinary users :
	# ------------------------------------
	# (has already been accomplished w/in /etc/skel, see above)


	# Complement PATH for root :
	# --------------------------

	if [ "$(id -u)" -eq  0 ]; then
		PATH=/sbin:/usr/sbin:/usr/lsbin:/usr/lsys:$PATH
	fi

	export PATH


	# (Edit the following entries) :
	# ------------------------------
	EDITOR=/usr/bin/vi
	BROWSER=opera:elinks:w3m
	LESS="-ix4 --LOG-FILE=$HOME/vv"
	HISTCONTROL=ignoreboth

	export EDITOR BROWSER LESS HISTCONTROL

	export LC_MESSAGES=en_US.UTF-8

	# Some Bash Functions working w/ Params
	# -------------------------------------

	lt ()   {
		ls -AltF $* | more
	}

	ltr ()   {
		ls -AltF $* | sort -r | more
	}

	# Create new (sub/)subdir and cd into:

	cdx ()   {
		md -p $1; test -d $1 && builtin cd $1
	}

	# display text file w/out empty or commented lines

	grep0	()	{
		grep -v ^# $* | grep -v ^$
	}	

	# rework bash aliases using etc/aliases.sh (OPTIONAL!, see below) :
	# ----------------------------------------------------------------
	# (create /etc/alias.sh to contain general aliases)

	unalias -a			# unset existing aliases
	. /etc/alias.sh		# set customized aliases
						# (see below)

	# =================================================
	# End of /etc/profile.local
	# =================================================


(6.) Create /etc/alias.sh containing general aliases (OPTIONAL!)
	 ===========================================================
	(examples:)

	alias 0=clear
	alias 00='dirs -c; cd; 0'

	alias l='clear; ls -alF'
	alias ll='ls -la'

	alias ,=cd
	alias ,,='00; cd ~; ls -alF'
	alias ..='cd ..'
	alias ...='cd ../..'
	alias +='cd /; dirs -c; l'

	alias pu=pushd
	alias po=popd

	alias md='mkdir -p'
	alias rd=rmdir
	
	alias c=cat
	alias g=gedit
	alias v=less
	alias z=zless
	alias vw=view
	alias vii='sudo vi'

	alias detab4='expand -t 4'
	alias detab8='expand -t 8'

==================================================================
==================================================================

(hope these instructions are sufficient)


Regards

Wilko


Reply to: