• Stars
    star
    18
  • Rank 1,168,896 (Top 24 %)
  • Language
    Shell
  • Created over 8 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

K get kool aliases (and more) working with a simple one-liner.

K

2016-02-06

K get kool aliases (and more) working with a simple one-liner.

Features

  • install with one line from the web
  • automatically re-organize your .bashrc in 4 files: aliases, functions, environment and sources
  • creating new aliases is easy
  • creating new functions is easy
  • adding new environment variables is easy
  • adding new sources is easy
  • since 1.1.0, ships with bashmarks

That's it.

How to use

Go to your home directory, then call the install url below

cd
source <(curl -s https://raw.githubusercontent.com/lingtalfi/k/master/script/k_installer.sh)

To see what this does, see the "k structure" section below.

Note: If you need to, there are other ways/options for the installer, see the installer section below.

Then, to edit/create an alias:

kalias

Once edited, source it by adding the s (for source) to the kalias command.

kaliass

This also works for functions, environment variables and sources.

# functions 
kfunc
kfuncs

# environment variables 
kenv
kenvs

# sources
ksource
ksources

You might ask what is source used for.

K use the term source for files that you want to source right off the bat, as you login. For instance, I personally use a framework to bookmark the location where I go, called bashmarks.

To configure it, I can edit the source file (using the ksource alias), and then put the following content in it:

. /home/ling/bin/bashmarks.sh

But note that since 1.1.0, bashmarks is automatically included (see next section).

As a bonus, there a few aliases for web standard programs that I use.

bashmarks

Since 1.1.0, you also have bashmarks shortcuts right away. Please refer to the bashmarks documentation for more details.

In a nutshell, here is a quick memo:

  • l: list
  • s $name: save current dir as $name
  • g $name: cd to dir $name
  • d $name: delete dir $name (from the bashmarks list)

The bashmarks puts its memory to your user's home/.sdirs file.

The k structure

When you one-line install k, it automatically creates the following structure in the current directory where you are (which should be your user's home directory):

- .k/ 
----- k_aliases.sh
----- k_functions.sh
----- k_environment_variables.sh
----- k_sources.sh

Then, it appends the following lines to your .bashrc (unless it's already there)

# kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
#  	 ____ 
# 	||K ||
# 	||__||
# 	|/__\|
#
# kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi

. "$DIR/.k/k_aliases.sh"
. "$DIR/.k/k_functions.sh"
. "$DIR/.k/k_environment_variables.sh"
. "$DIR/.k/k_sources.sh"

Those special files are called "k files". They are all empty by default, except the k_aliases file, which contains some useful aliases (see k native aliases section).

k native aliases

#-------------------------------------
# K NATIVE ALIASES
#-------------------------------------
alias kalias='vim ~/.k/k_alias.sh'
alias kaliass='. ~/.k/k_alias.sh'
alias kfunc='vim ~/.k/k_functions.sh'
alias kfuncs='. ~/.k/k_functions.sh'
alias kenv='vim ~/.k/k_environment_variables.sh'
alias kenvs='. ~/.k/k_environment_variables.sh'
alias ksource='vim ~/.k/k_sources.sh'
alias ksources='. ~/.k/k_sources.sh'


#-------------------------------------
# MAIN PROGRAM LOGS AND SERVICE 
#-------------------------------------
# the principe is to start with the first letter of the service twice,
# followed by log for error log, and alog for access log (web server only)

alias aalog='tail -f /var/log/apache2/error.log'
alias aaalog='tail -f /var/log/apache2/access.log'
alias aar='service apache2 restart'

alias nnlog='tail -f /var/log/nginx/error.log'
alias nnalog='tail -f /var/log/nginx/access.log'
alias nnr='service nginx restart'

alias sslog='tail -f /var/log/syslog'

alias hhlog='tail -f /var/log/auth.log'





The default editor to open files is vim, but it can be changed when you invoke the install program (first argument).

k native functions

mcd () { mkdir -p "$1" && cd "$1"; }

path () {
  echo $PATH | tr ':' '\n' | xargs ls -ld 
}

importconf () {
    # todo: import ling's tmux or ling's git confs
}

Tips

Since k installs itself wherever you currently are, a good tip that you can use if you want to create all your users with a default k skin is to cd to /etc/skel, and then call the k installer. Here is an example:

# (be root)
cd /etc/skel
source <(curl -s https://raw.githubusercontent.com/lingtalfi/k/master/script/k_installer.sh)

Now, the next time you create an user, she will have the k skin right off the bat.

Ideas

Create a native function that copies the k dir to another user's home directory (and configure the .bashrc)

Installer

The installer is simply a bash script that does the installation of the k program.

Although it doesn't require parameters, it the installer accepts a maximum of two parameters.

  • the first argument is the editor used to open the files (some of the k native aliases use this editor). The default is vim, but you can change it to anything you like: nano for instance, or even the mac specific open command. Have a look at the examples below.

  • The second argument decide whether or not the installer should override your existing configuration.

          By default, the installer checks for the existence of the **.k** directory in the current directory.
          If the .k directory exists, the installer does nothing.
          This is generally what we want.
          
          However, it is possible to tell the installer to override your current .k directory, no matter what.
          To do so, you use the second argument, called **override** and set its value to 1.
                       
          Generally, this is a bad idea, but I added it for personal purposes (details are not very interesting),
          and I wanted you to be aware of it.
    

Here are different ways to call the installer, some examples use wget, some other use curl.

# default example
source <(curl -s https://raw.githubusercontent.com/lingtalfi/k/master/script/k_installer.sh)


# alternative using nano as the default editor instead of vim
curl -s https://raw.githubusercontent.com/lingtalfi/k/master/script/k_installer.sh | bash /dev/stdin nano

# alternative using open (mac) as the default editor instead of vim
curl -s https://raw.githubusercontent.com/lingtalfi/k/master/script/k_installer.sh | bash /dev/stdin open

# wget alternative 
bash <(wget -qO- https://raw.githubusercontent.com/lingtalfi/k/master/script/k_installer.sh)

# wget alternative using nano as the default editor instead of vim
wget -qO- https://raw.githubusercontent.com/lingtalfi/k/master/script/k_installer.sh | bash -s -- nano

History Log

  • 1.2.2 -- 2016-02-07

    • add nnconf alias to edit nginx.conf
  • 1.2.1 -- 2016-02-06

    • add ffconf alias to edit php-fpm www.conf
  • 1.2.0 -- 2016-02-06

    • add php-fpm aliases
    • add override mechanism to force re-install
  • 1.1.0 -- 2016-02-06

    • add bashmarks to the default install
  • 1.0.0 -- 2016-02-06

    • initial commit

More Repositories

1

bashmanager

mini bash framework for creating command line tools
Shell
88
star
2

simpledrag

simple drag function in vanilla js
JavaScript
48
star
3

video-ids-and-thumbnails

Some php functions to access the ids and thumbnails of youtube, vimeo and dailymotion
PHP
43
star
4

TheBar

Various discussions about the universe and everything
19
star
5

ffmpeg-notes

Some random notes that I found useful while working with ffmpeg
17
star
6

task-manager

A task manager for your daily tasks
Shell
14
star
7

newFileWithPrompt

On mac, create a new file in one click and prompting you for the filename
14
star
8

dimensions-cheatsheet

Dimensions of an element in javascript, cheatsheet
11
star
9

logrotator

a simple log rotator written in bash
Shell
10
star
10

Bat

Basic tools for php
PHP
7
star
11

videojs-ad-markers

Plugin for videojs to provide common functionality needed to implement a advertising system
JavaScript
7
star
12

where-is-focus-bookmarklet

A bookmarklet that console.log the element which has focus
7
star
13

count-dom-nodes-bookmarklet

A bookmarklet that alerts how many DOM nodes you have on your page
6
star
14

mac-terminal-shortcuts

Intuitive editing shortcuts for the Mac Os X terminal
6
star
15

printScriptDir

get the bash script's real directory
Shell
6
star
16

symfony-cheatsheet

my symfony cheatsheet
5
star
17

JAjaxLoader

A jquery plugin to start/stop an ajax loader
CSS
5
star
18

ling-gallery-filter

A simple jquery plugin to filter items based on their categories.
JavaScript
4
star
19

Ingenico

Helper tools for implementing ingenico payment solutions
PHP
4
star
20

my-svelte-component

This is my template for a svelte component.
JavaScript
4
star
21

fullcalendar-php-services

Php implementation of fullcalendar basic interactions
JavaScript
3
star
22

YouTubeUtils

Tools to manipulate Youtube Apis
PHP
3
star
23

jChronometer

A javascript chronometer
JavaScript
3
star
24

webmaster-wizard

Administrative webmaster tasks centralized in a command
PHP
2
star
25

BashColorTool

A tool to create quick colored messages in console.
PHP
2
star
26

bash-functions-library

A library of bash functions
2
star
27

ArrayToTable

Create an html table from a php array
PHP
2
star
28

log-change-notify

Detect change in a log file and send an email
Shell
2
star
29

SvgGridGenerator

Create css grid lines
PHP
1
star
30

myaliases

my bash aliases in the cloud
Shell
1
star
31

VideoSubtitles

Tools to work with subtitles
PHP
1
star
32

simplegrid

A css grid light-weight framework
CSS
1
star
33

kaminos

An administration system for any website
HTML
1
star
34

melp

Simple memory assistant for your computer
Shell
1
star
35

MysqlTabular

Generate a mysql table with the "console" format
PHP
1
star
36

WebBox

Some tools to build common php based webservices.
PHP
1
star
37

calias

bash script that makes a command available system wide rapidly
Shell
1
star
38

ArrayToString

Converts a php array to a string
PHP
1
star
39

simplesidebar

A simple sidebar widget written in jquery.
CSS
1
star
40

Here

Helper to represent events on an horizontal timeline
JavaScript
1
star
41

umail

A helper class to send mails
HTML
1
star
42

jquery-validation-rib

This is a plugin for jquery-validation that validates a rib (national bank account number in France)
JavaScript
1
star
43

zquery

A minimalist javascript library for your projects
JavaScript
1
star
44

jInfiniteSlider

Simple jquery infinite (circular) slider
JavaScript
1
star
45

cdd

Go fast to any directory via a bookmarks bash system
Shell
1
star
46

XiaoApi

Create a consistent api based on a crud model
PHP
1
star
47

bomb

A command line sugar to remove files and dirs
Shell
1
star
48

JCookie

A javascript library to handle cookies
JavaScript
1
star
49

bashmanager_plugin_phpmanager

php plugin for bash manager
PHP
1
star
50

MysqlCreateTableUtil

A tool to create a basic mysql create table statement.
PHP
1
star
51

jVideoPlayer

A javascript library to help building a video player
JavaScript
1
star
52

jItemSlider

Simple responsive jquery infinite (circular) slider, based on items
JavaScript
1
star