Compare commits
No commits in common. "e489e29a4bd313b1e8b4ff8796d21f1e8128cdd2" and "19a6e62712fd84dd941776d375692483f4e914a4" have entirely different histories.
e489e29a4b
...
19a6e62712
53 changed files with 1738 additions and 1079 deletions
10
.gitignore
vendored
10
.gitignore
vendored
|
@ -1,8 +1,2 @@
|
|||
auto-save-list
|
||||
elpa
|
||||
config.el
|
||||
smex-items
|
||||
recentf
|
||||
transient
|
||||
ido.last
|
||||
config.el
|
||||
src/*.o
|
||||
src/bin/
|
||||
|
|
160
CHANGELOG
Normal file
160
CHANGELOG
Normal file
|
@ -0,0 +1,160 @@
|
|||
96d5493 Fixed stuff in rmdir
|
||||
74047ab proto -l in ls
|
||||
8a477a0 trying EBIN indentation style :-------DDDDDDDDDDDD
|
||||
fbff968 wait i'm fucking stupid, lmao, well musl, good luck searching for a file called -<CHAR>, but if it makes you happy, go for it my dude
|
||||
e4192c6 don't take - as stdin if it is a flag (solves musl getopt() bullshit)
|
||||
dc61ade sorry, my emacs indentation was retarded
|
||||
342a885 less long line
|
||||
dd949ba Tabs instead of spaces in indentation lol
|
||||
34a3f38 added contributing guideliness
|
||||
609309e im an idiot
|
||||
36f49ec cat: ignore -u and - can be used for stdin
|
||||
8627b3b shit to cat.c read the diff lmao
|
||||
997b2ed https://lainsafe.delegao.moe/files/160545969573108.png
|
||||
cc03664 Cleanup code
|
||||
c322cdd %c is better since gnu date gives that by default so take it
|
||||
b0ca123 Added a probably non posix compliant date(1) but it works :DDD
|
||||
8dc1039 Added the -p flag to ls
|
||||
a43985b Holy cow, I added comments but I made another commit to k9core!
|
||||
1d78c2c It seems that, somehow, i typed 1 instead of 0
|
||||
8f16928 POSIX, I don't really get you sometimes...
|
||||
f487111 Added tee!
|
||||
8eed6cc added -h flag to chgrp
|
||||
b244eb3 added chgrp
|
||||
ea00641 wc prints the filename
|
||||
21718a0 Modified the style
|
||||
571b6c7 Is this ok, POSIX?
|
||||
98f9bd9 Remove useless headers
|
||||
016c4f6 Whatever this does lmao
|
||||
20eb8d5 cleaned up chmod.c
|
||||
0a5169b generic case for uname
|
||||
8cde471 what the hell is -m flag posix is literally the same as -c
|
||||
9713636 Finally fixed wc :D
|
||||
4d96265 Improved uname.c
|
||||
d8c6dd6 Modified the readme because this also has util-linux packes
|
||||
7f38565 git you're a bit dumb
|
||||
a8ae0f1 moved non coreutils programs to a nonuserland folder since they are not userland programs
|
||||
b653b75 Better style and stuff to uname.c
|
||||
2b3baec In GNU's uname(1) if you pass no arguments it prints the kernel name so mine does that too.
|
||||
41fac48 Added uname, works but probably not as it should, initial commit for this and i'll fix it if needed later (probably i forgot some flags, programming is hard)
|
||||
7f4a6e2 added chroot
|
||||
dfa79c9 im stupid
|
||||
015f021 added cat the posix -u flag which is useless
|
||||
07c86b1 Improved makefile
|
||||
30bc675 added a bunch of programs
|
||||
d832f81 added groups
|
||||
f0712c3 lmao
|
||||
e5464f8 Added logname.c differences with whoami.c: * whoami prints who you are * logname prints the username you logged with meaning that if you run logname with doas(1) or sudo(8) you'll get the real username instead of root
|
||||
cd73c58 tty(1), which prints the name of the teletypewriter you're using.
|
||||
fdd3579 improved sleep by using usleep() instead of sleep() which allows more precise times
|
||||
0d806ef add sync
|
||||
cb32179 added ernno things
|
||||
2d60914 im a bit dumb you know
|
||||
32e3a82 lol
|
||||
069bde6 i kinda hate posix because -n, but there it is i just have to add a for loop so it iterates every file passed by args
|
||||
642d6f3 added head
|
||||
61a4887 modified kill.c so doesn't use getopt (which in this case was a complete overkill). Also a warning if nothing given.
|
||||
0d9b8f2 sleep
|
||||
0f8f9dc exec
|
||||
fecba9a Almost done wc only pick from stdin if no file given. but all flags are working!
|
||||
dcf829a somebody pls fix flags and stdin
|
||||
3a44055 Merge branch 'master' of gitlab.com:call-cc/k9core into master
|
||||
8d1bf0e added flags to wc
|
||||
1a37413 improve ls (make it look cleaner)
|
||||
371c5f0 What the fuck is this
|
||||
c0935a1 added errno to ln.c
|
||||
0ee58eb idk whats this git told me isnt' staged so hre's your commit
|
||||
a1f38d5 Edited some stuff in wc and mv
|
||||
bb78561 Fixed shred
|
||||
7bedf74 use stat() instead of a own function to count bytes.
|
||||
ab00cba Added shred
|
||||
801cf9d Added unlink, not really sure of that this do but well here it is
|
||||
3823f62 less bad mv
|
||||
9c856f4 yeah so now the thing closes the file descriptors
|
||||
2996e21 cp now supports binary data and touch.c uses the saner creat() instead of open() because using open() there was simply stupid
|
||||
1d8f3bf fprintf in mount.c
|
||||
59d1ef6 Better errno
|
||||
b574d18 added id.c.
|
||||
43d55a3 -f flag for umount.c (now we use umount2 though)
|
||||
636072c lol
|
||||
69d0fae Added stuff to mount.c
|
||||
8065fed Better whoami
|
||||
7d414e2 Mount and whoami
|
||||
7cb95b3 added umount
|
||||
755222a I just do a prototype of mkdir -p that does not work because it does not work so is commented don't uncomment it unless you can fix it thank you
|
||||
b339661 Merge branch 'master' of gitlab.com:call-cc/k9core
|
||||
5238638 Added -l to kill.c
|
||||
b263799 Fix to remove error in -Wall -Wextra
|
||||
87c139e Fix ln slightly by removing instead of unlinking.
|
||||
2401662 whoops
|
||||
f317faa Aded cp and mv
|
||||
61245b5 This will save a lot of time
|
||||
e1e3f9f more readable cat.c
|
||||
c037341 Cat prints binary data now
|
||||
c904af6 Someone make this read binary shit
|
||||
268a888 Rewritten cat so it's not literally 9base's
|
||||
9d6db6f Improved wc
|
||||
971e32a bare bones version of wc
|
||||
e4c35b7 unistd.h was useless in ls.c
|
||||
8ac5f0b Add -a flag for ls.
|
||||
8c81a09 Do not print dot files in ls.c
|
||||
a6bfb92 Added ls.c
|
||||
530bb5c Added chown.c
|
||||
f4dc088 Added variable guidelines
|
||||
1c6f622 Improve echo, or fix -n flag
|
||||
538adce printf -> fprintf in src/chmod.c
|
||||
60b3510 Added chmod
|
||||
d2be0fe Added false and true
|
||||
aff3c77 Readme in org
|
||||
a4d4d90 Fixed style in src/echo.c
|
||||
82b36c8 Clean code in src/echo.c
|
||||
73ab1c7 Sorry i haven't slept in 21 hours
|
||||
2f5f39a goddammit
|
||||
eba3830 I don't know I was really drunk at the time
|
||||
e4cdd7d slight fix
|
||||
2214494 Add -n flag to echo
|
||||
79ec3ad License update
|
||||
4ca78b4 Improve makefile and mark ln as complete
|
||||
85f3c31 I don't know how to use gdb
|
||||
8adf347 Switch statement
|
||||
9c7fec7 Added kill
|
||||
559fd48 Change STYLE.ORG file name because it trips up gitlab
|
||||
c1115b3 Add to README
|
||||
81244ae Add to TODO and migrate to the kill-9 public license
|
||||
e27abc9 Improve yes
|
||||
0670f46 Fix errors in style, plus more stuff about C standardization
|
||||
02699d5 Add error alert to ln and another item to the todo
|
||||
fbacc8d Style written in org
|
||||
bc423b1 Add todo.org, fix pwd.c
|
||||
8dcc572 Added new style thing
|
||||
f4e746e Change errors in rmdir to warns
|
||||
9486a50 Add -f flag to ln
|
||||
f458b93 More makefile improvements
|
||||
e4758c0 Remove note, improve makefile
|
||||
66dbeda I hate git.
|
||||
36adf54 Fixed makefile
|
||||
fe104b8 Merge branch 'master' of https://gitlab.com/call-cc/k9core
|
||||
c68d449 Add note to ln.c
|
||||
bdbe212 Add to TODO and clean up ln
|
||||
14e32f3 Improved makefile
|
||||
3843efd Tried to add symlinks the worst way possible. Please fix
|
||||
0575e4d Add ln
|
||||
87681f9 Added yes
|
||||
976d1ed idk why is this merge important tbh Merge branch 'master' of gitlab.com:call-cc/k9core
|
||||
62ecbde Added src/mkdir.c, src/rm.c, some tips for commiters and close file descriptor in src/touch.c
|
||||
30192ae Adhere to style guidelines
|
||||
cb17679 added coding style guide
|
||||
d4eb349 Make dirname more posix compliant
|
||||
d2c5b8a Add dirname
|
||||
83af9b4 Errors count to rmdir
|
||||
9077404 Rewritten rmdir
|
||||
5450b0c add multiple-argument deletion to rmdir
|
||||
35c7b05 Add rmdir
|
||||
7db446d Add makefile
|
||||
ff4f7c1 Added touch
|
||||
36b7302 Add README
|
||||
ba25b37 Add pwd
|
||||
152ad26 Very slight cat fix
|
||||
602dd40 Fix echo, shorten file size
|
||||
9301665 Add echo
|
||||
0e055db Initial commit
|
29
LICENSE
29
LICENSE
|
@ -1,13 +1,24 @@
|
|||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
|
|
7
README.org
Normal file
7
README.org
Normal file
|
@ -0,0 +1,7 @@
|
|||
* k9core
|
||||
|
||||
Extremely minimalist coreutils. It also includes some util-linux
|
||||
packages
|
||||
|
||||
** License
|
||||
Licensed under the k9pl. See LICENSE for more information.
|
807
config.org
807
config.org
|
@ -1,807 +0,0 @@
|
|||
#+TITLE: emacs config
|
||||
|
||||
* suragu's Emacs config
|
||||
|
||||
This is my Emacs configuration, if you don't like it, that's ok
|
||||
because I made it thinking of myself. the code here is tidy
|
||||
so anyone could modify it without great pain.
|
||||
|
||||
** Installation
|
||||
Just copy this repository to your emacs configuration path. Nothing
|
||||
else is needed.
|
||||
* Why?
|
||||
- I can
|
||||
- I don't like doom emacs
|
||||
- I don't like spacemacs
|
||||
- I don't want to learn doom emacs
|
||||
- I don't want to learn spacemacs
|
||||
- I don't like Vim
|
||||
|
||||
* gc
|
||||
#+begin_src emacs-lisp
|
||||
;; Minimize garbage collection during startup
|
||||
(setq gc-cons-threshold most-positive-fixnum)
|
||||
|
||||
;; Lower threshold back to 8 MiB (default is 800kB)
|
||||
(add-hook 'emacs-startup-hook
|
||||
(lambda ()
|
||||
(setq gc-cons-threshold (expt 2 23))))
|
||||
#+end_src
|
||||
* melpa crap, and basic packages installation
|
||||
melpa, where you get the packages. This also installs use-package,
|
||||
and other packages I use.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(require 'package)
|
||||
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
|
||||
(not (gnutls-available-p))))
|
||||
(proto (if no-ssl "http" "https")))
|
||||
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
|
||||
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
|
||||
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
|
||||
(when (< emacs-major-version 24)
|
||||
;; For important compatibility libraries like cl-lib
|
||||
(add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
|
||||
|
||||
(if (< emacs-major-version 27)
|
||||
(package-initialize))
|
||||
(unless (package-installed-p 'use-package)
|
||||
(package-refresh-contents)
|
||||
(package-install 'use-package))
|
||||
#+END_SRC
|
||||
** Generic packages
|
||||
Here I install some packages that don't need configuration.
|
||||
Remember to run M-x all-the-icons-install-fonts after the first
|
||||
init to install the fonts.
|
||||
#+BEGIN_SRC elisp
|
||||
|
||||
(use-package markdown-mode
|
||||
:defer 1
|
||||
:ensure t
|
||||
:init(add-hook 'markdown-mode-hook 'auto-fill-mode))
|
||||
(use-package all-the-icons
|
||||
:defer 1
|
||||
:ensure t)
|
||||
(use-package which-key
|
||||
:ensure t
|
||||
:init (which-key-mode))
|
||||
#+END_SRC
|
||||
* Autoindentation
|
||||
C-c n for indent-buffer. I don't use the rest.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq-default tab-width 5)
|
||||
(defvaralias 'sgml-basic-offset 'tab-width)
|
||||
(add-hook 'html-mode-hook
|
||||
(lambda ()
|
||||
(set-fill-column 100)))
|
||||
(add-hook 'markdown-mode-hook
|
||||
(lambda ()
|
||||
(set-fill-column 75)))
|
||||
|
||||
|
||||
(defun indent-buffer ()
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(indent-region (point-min) (point-max) nil)))
|
||||
(global-set-key (kbd "C-c n") 'indent-buffer)
|
||||
;; C bullshit
|
||||
(c-set-offset 'arglist-cont-nonempty '+)
|
||||
#+END_SRC
|
||||
|
||||
* Shorcuts
|
||||
Probably this overwrites another keybinding. But since I overwrited
|
||||
it. I don't think i'd ever use the overwritten.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(global-set-key (kbd "M-m") 'mark-whole-buffer)
|
||||
(global-set-key (kbd "C-c m") 'man)
|
||||
(define-key org-mode-map (kbd "C-c p") 'org-publish-current-file)
|
||||
<<<<<<< HEAD
|
||||
(set-frame-font "Monospace 12")
|
||||
||||||| parent of 5575988 (no se ni que he hecho)
|
||||
(set-frame-font "Hack 17")
|
||||
=======
|
||||
>>>>>>> 5575988 (no se ni que he hecho)
|
||||
#+END_SRC
|
||||
|
||||
* No idea
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq package-enable-at-startup nil) (package-initialize)
|
||||
(setq make-backup-files nil) ; stop creating backup~ files
|
||||
(setq auto-save-default nil) ; stop creating #autosave# files
|
||||
(put 'upcase-region 'disabled nil)
|
||||
(defun contextual-menubar (&optional frame)
|
||||
"Display the menubar in FRAME (default: selected frame) if on a
|
||||
graphical display, but hide it if in terminal."
|
||||
(interactive)
|
||||
(set-frame-parameter frame 'menu-bar-lines
|
||||
(if (display-graphic-p frame)
|
||||
1 0)))
|
||||
(add-hook 'after-make-frame-functions 'contextual-menubar)
|
||||
(use-package zencoding-mode
|
||||
:ensure t
|
||||
:defer 1)
|
||||
#+END_SRC
|
||||
* My functions
|
||||
Functions I wrote because emacs lisp is cool and useful.
|
||||
#+begin_src emacs-lisp
|
||||
(defun sosa/goto-previous-buffer ()
|
||||
"Switch to the previous buffer."
|
||||
(interactive)
|
||||
(switch-to-buffer (other-buffer)))
|
||||
|
||||
(defun sosa/kill-inner-word ()
|
||||
"Unlike (kill-word) function, this function actually kill a world."
|
||||
(interactive)
|
||||
(forward-char 1)
|
||||
(backward-word)
|
||||
(kill-word 1))
|
||||
(defun sosa/no-lines()
|
||||
"Locally disable number line mode, useful hooks."
|
||||
(display-line-numbers-mode -1))
|
||||
|
||||
(defun sosa/git-pushall ()
|
||||
"Call the git pushall shell command."
|
||||
(interactive)
|
||||
(shell-command "git pushall"))
|
||||
|
||||
(defun sosa/goto-dashboard ()
|
||||
"Goes to the dashboard buffer"
|
||||
(interactive)
|
||||
(switch-to-buffer "*dashboard*")
|
||||
(dashboard-mode)
|
||||
(dashboard-refresh-buffer))
|
||||
|
||||
(setq org-publish-project-alist
|
||||
'(("suragu.net"
|
||||
:base-directory "~/docs/qorg_qorg/"
|
||||
:publishing-directory "~/docs/mounts/suragu"
|
||||
:section-numbers nil
|
||||
:publishing-function org-html-publish-to-html
|
||||
:table-of-contents nil
|
||||
:recursive t
|
||||
)))
|
||||
|
||||
(defun sosa/make-website ()
|
||||
"Publish the .org files of suragu.net to the sshfs mountpoint"
|
||||
(interactive)
|
||||
(org-publish "suragu.net"))
|
||||
|
||||
(defun run-current-file ()
|
||||
"Execute or compile the current file.
|
||||
For example, if the current buffer is the file x.pl,
|
||||
then it'll call “perl x.pl” in a shell.
|
||||
The file can be php, perl, python, bash, java.
|
||||
File suffix is used to determine what program to run."
|
||||
(interactive)
|
||||
(let (ext-map file-name file-ext prog-name cmd-str)
|
||||
; get the file name
|
||||
; get the program name
|
||||
; run it
|
||||
(setq ext-map
|
||||
'(
|
||||
("php" . "php")
|
||||
("pl" . "perl")
|
||||
("py" . "python")
|
||||
("p6" . "raku")
|
||||
("raku" . "raku")
|
||||
("sh" . "bash")
|
||||
("java" . "javac")
|
||||
)
|
||||
)
|
||||
(setq file-name (buffer-file-name))
|
||||
(setq file-ext (file-name-extension file-name))
|
||||
(setq prog-name (cdr (assoc file-ext ext-map)))
|
||||
(setq cmd-str (concat prog-name " " file-name))
|
||||
(shell-command cmd-str)))
|
||||
|
||||
(defun sosa/repos ()
|
||||
(interactive)
|
||||
(dired "/home/diego/Escritorio/zpool/repos/"))
|
||||
(global-set-key (kbd "C-c r") 'sosa/repos)
|
||||
#+end_src
|
||||
* Programs
|
||||
Emacs customization, Here is where most of the configuration is.
|
||||
** Pseudopersonalization
|
||||
Sane defaults!!!
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(tool-bar-mode -1)
|
||||
(menu-bar-mode -1)
|
||||
(scroll-bar-mode -1)
|
||||
(global-hl-line-mode)
|
||||
(set-face-background hl-line-face "#434343")
|
||||
(setq-default cursor-type 'box)
|
||||
(blink-cursor-mode 1)
|
||||
(setq-default major-mode 'text-mode)
|
||||
(defalias 'yes-or-no-p 'y-or-n-p)
|
||||
;; Are you experienced?
|
||||
|
||||
(set-face-background 'line-number nil)
|
||||
(set-face-background 'line-number-current-line nil)
|
||||
(setq-default Man-notify-method 'pushy)
|
||||
#+END_SRC
|
||||
** Highlight matching parentheses
|
||||
Useful for programming in lisp. I don't program in Lisp, but well.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(show-paren-mode 1)
|
||||
(setq show-paren-style 'mixed)
|
||||
|
||||
(setq startup/gc-cons-threshold gc-cons-threshold)
|
||||
(setq gc-cons-threshold most-positive-fixnum)
|
||||
(defun startup/reset-gc () (setq gc-cons-threshold startup/gc-cons-threshold))
|
||||
(add-hook 'emacs-startup-hook 'startup/reset-gc)
|
||||
#+END_SRC
|
||||
** Tramp mode shit
|
||||
(basically) no limit for remote files.
|
||||
#+begin_src emacs-lisp
|
||||
(set-variable 'tramp-copy-size-limit 122222222222)
|
||||
(set-variable 'tramp-inline-compress-start-size 12222222222222)
|
||||
#+end_src
|
||||
** Lines and columns
|
||||
Show relative lines in each file. Also display the column in the
|
||||
minibuffer.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(global-display-line-numbers-mode 1)
|
||||
(setq display-line-numbers-type 'relative)
|
||||
(column-number-mode 1)
|
||||
#+END_SRC
|
||||
** Flycheck
|
||||
Flycheck is a syntax validator and lintern for programming.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package flycheck
|
||||
:ensure t)
|
||||
#+END_SRC
|
||||
And for raku
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package flycheck-raku
|
||||
:ensure t
|
||||
:init
|
||||
(add-hook 'raku-mode 'flycheck-raku-mode))
|
||||
#+END_SRC
|
||||
|
||||
** Terminal
|
||||
vterm is better than ansi-term and shit, despite it's kinda slow,
|
||||
it's a price i'm willing to pay. Remember that to compile VTerm you
|
||||
need =cmake= installed. See the error buffer that is created everytime
|
||||
you try to copmile vterm for further information.
|
||||
|
||||
It should use your default shell by default.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package "vterm"
|
||||
:ensure t)
|
||||
#+END_SRC
|
||||
And to have multiple buffers
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package multi-vterm
|
||||
:ensure t
|
||||
:bind("C-x C-t" . multi-vterm))
|
||||
#+END_SRC
|
||||
** Theme
|
||||
#+begin_src emacs-lisp
|
||||
<<<<<<< HEAD
|
||||
(use-package "base16-theme"
|
||||
||||||| parent of 5575988 (no se ni que he hecho)
|
||||
(use-package "exotica-theme"
|
||||
=======
|
||||
(use-package "zweilight-theme"
|
||||
>>>>>>> 5575988 (no se ni que he hecho)
|
||||
:ensure t
|
||||
<<<<<<< HEAD
|
||||
:init(load-theme 'base16-black-metal-bathory t)
|
||||
)
|
||||
||||||| parent of 5575988 (no se ni que he hecho)
|
||||
:init(load-theme 'exotica t)
|
||||
)
|
||||
=======
|
||||
:init(load-theme 'zweilight t))
|
||||
(set-frame-font "Inconsolata 15")
|
||||
>>>>>>> 5575988 (no se ni que he hecho)
|
||||
(set-cursor-color "purple")
|
||||
|
||||
#+end_src
|
||||
** ctrlf
|
||||
So, you know, C-s in emacs sucks, so this is a repleacement for that.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package ctrlf
|
||||
:ensure t
|
||||
:defer 1
|
||||
:init
|
||||
(ctrlf-mode +1))
|
||||
#+END_SRC
|
||||
|
||||
** Programming language things
|
||||
*** Lisp
|
||||
Parentheses highlight in lisp modes. So you can easily identify
|
||||
them.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package rainbow-delimiters
|
||||
:ensure t
|
||||
:init
|
||||
(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)
|
||||
(add-hook 'lisp-mode-hook 'rainbow-delimiters-mode)
|
||||
(add-hook 'scheme-mode-hook 'rainbow-delimiters-mode))
|
||||
|
||||
(setq lisp-indent-offset 5)
|
||||
#+END_SRC
|
||||
*** Perl
|
||||
I use LSP for perl.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq perl-indent-level 5)
|
||||
(defalias 'perl-mode 'cperl-mode)
|
||||
(add-hook 'perl-mode-hook (lambda ()
|
||||
<<<<<<< HEAD
|
||||
(lsp)
|
||||
(irony-mode -1)))
|
||||
(load-file "~/.config/emacs/perltidy.el")
|
||||
||||||| parent of 5575988 (no se ni que he hecho)
|
||||
(lsp)
|
||||
(irony-mode -1)))
|
||||
=======
|
||||
(lsp)))
|
||||
(load-file "~/.config/emacs/perltidy.el")
|
||||
>>>>>>> 5575988 (no se ni que he hecho)
|
||||
#+END_SRC
|
||||
*** C*
|
||||
This use c-eldoc mode so it prints the function's prototype in the
|
||||
minibuffer. Which is very useful since Irony works when it wants
|
||||
to. LSP is also used for further Programming.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package c-eldoc
|
||||
:ensure t
|
||||
:init
|
||||
(add-hook 'c-mode-hook 'c-turn-on-eldoc-mode))
|
||||
(setq c-default-style "k&r")
|
||||
(add-hook 'c-mode-hook (lambda ()
|
||||
(lsp)))
|
||||
#+END_SRC
|
||||
*** Raku
|
||||
Raku, the cornerstone of any well designed programming language.
|
||||
#+begin_src emacs-lisp
|
||||
(setq raku-indent-offset 5)
|
||||
(setq raku-exec-path "/home/diego/.local/bin/raku")
|
||||
#+end_src
|
||||
*** HTML & CSS offset
|
||||
#+begin_src emacs-lisp
|
||||
(setq css-indent-offset 5)
|
||||
(setq sgml-basic-offset 5)
|
||||
#+end_src
|
||||
*** org
|
||||
#+begin_src emacs-lisp
|
||||
(setq org-ellipsis " ")
|
||||
(setq org-src-fontify-natively t)
|
||||
(setq org-src-tab-acts-natively t)
|
||||
(setq org-confirm-babel-evaluate nil)
|
||||
(setq org-export-with-smart-quotes t)
|
||||
(setq org-src-window-setup 'current-window)
|
||||
(add-hook 'org-mode-hook 'org-indent-mode)
|
||||
(add-hook 'org-mode-hook 'sosa/no-lines)
|
||||
;; Syntax highlighting in exports
|
||||
(use-package htmlize
|
||||
:ensure t)
|
||||
(setq org-html-head ""
|
||||
org-html-head-extra ""
|
||||
org-html-head-include-default-style nil
|
||||
org-html-head-include-scripts nil
|
||||
org-html-preamble nil
|
||||
org-html-postamble nil
|
||||
org-html-use-infojs nil)
|
||||
#+end_src
|
||||
|
||||
** Keybindings
|
||||
Here I put functions I won't bother to document because they're so
|
||||
simple.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(global-set-key (kbd "M-d") 'sosa/kill-inner-word)
|
||||
(global-set-key (kbd "M-.") 'repeat)
|
||||
(global-set-key (kbd "C-x k") 'kill-buffer)
|
||||
(global-set-key (kbd "C-x C-k") 'kill-current-buffer)
|
||||
(global-unset-key (kbd "C-x C-b"))
|
||||
(global-set-key (kbd "C-x C-b") 'sosa/goto-previous-buffer)
|
||||
#+END_SRC
|
||||
** Hunspell
|
||||
For some reason, there is no ispell spanish in void linux. so i had
|
||||
to fallback to hunspell. which does the same.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defvar ispell-program-name "hunspell") ;; Or whatever you use
|
||||
;; (ispell, aspell...)
|
||||
|
||||
#+END_SRC
|
||||
** Dired
|
||||
Ahhh, the emacs file browser, better than ranger and others...
|
||||
Hide dotfiles:
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
|
||||
(use-package dired-hide-dotfiles
|
||||
:ensure t
|
||||
:init
|
||||
(defun my-dired-mode-hook ()
|
||||
"My `dired' mode hook."
|
||||
;; To hide dot-files by default
|
||||
(dired-hide-dotfiles-mode)
|
||||
|
||||
;; To toggle hiding
|
||||
(define-key dired-mode-map "." #'dired-hide-dotfiles-mode))
|
||||
|
||||
(add-hook 'dired-mode-hook #'my-dired-mode-hook))
|
||||
(use-package async
|
||||
:ensure t
|
||||
:init (dired-async-mode 1))
|
||||
(add-hook 'dired-mode-hook
|
||||
(lambda ()
|
||||
(dired-hide-details-mode)))
|
||||
#+END_SRC
|
||||
Now let's make the thing lysergic
|
||||
#+begin_src emacs-lisp
|
||||
(set-face-foreground dired-directory-face "orange")
|
||||
(set-face-foreground dired-symlink-face "cyan")
|
||||
(set-face-foreground dired-mark-face "green")
|
||||
(set-face-foreground dired-marked-face "blue")
|
||||
#+end_src
|
||||
Good sorting
|
||||
#+begin_src emacs-lisp
|
||||
(setq dired-listing-switches "-aBhl --group-directories-first")
|
||||
#+end_src
|
||||
** kill ring popup
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package popup-kill-ring
|
||||
:ensure t
|
||||
:bind ("M-y" . popup-kill-ring))
|
||||
|
||||
#+END_SRC
|
||||
|
||||
** scrolling
|
||||
Scroll by lines rather than by pages.
|
||||
#+begin_src emacs-lisp
|
||||
(setq scroll-step 1)
|
||||
(setq scroll-conservatively 10000)
|
||||
(setq auto-window-vscroll nil)
|
||||
#+end_src
|
||||
** Shell
|
||||
#+begin_src emacs-lisp
|
||||
(add-hook 'shell-mode-hook 'yas-minor-mode)
|
||||
(add-hook 'shell-mode-hook 'flycheck-mode)
|
||||
(add-hook 'shell-mode-hook 'company-mode)
|
||||
|
||||
(defun shell-mode-company-init ()
|
||||
(setq-local company-backends '((company-shell
|
||||
company-shell-env
|
||||
company-etags
|
||||
company-dabbrev-code))))
|
||||
|
||||
(use-package company-shell
|
||||
:ensure t
|
||||
:config
|
||||
(require 'company)
|
||||
(add-hook 'shell-mode-hook 'shell-mode-company-init))
|
||||
#+end_src
|
||||
|
||||
** Mark multiple
|
||||
Multiple cursors :DD
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "multiple-cursors"
|
||||
:ensure t
|
||||
:bind ("C-x q" . 'mc/mark-next-like-this))
|
||||
|
||||
#+end_src
|
||||
|
||||
** Highlight indent guides
|
||||
I don't really know, it looks cool.
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "highlight-indent-guides"
|
||||
:ensure t
|
||||
:defer
|
||||
:init (add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
|
||||
(setq highlight-indent-guides-method 'bitmap))
|
||||
#+end_src
|
||||
** Ace jump mode
|
||||
Run, live to fly
|
||||
Fly to live, do or die
|
||||
Won't you run, live to fly
|
||||
Fly to live, aces high
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "ace-jump-mode"
|
||||
:ensure t
|
||||
:bind("C-l" . 'ace-jump-mode))
|
||||
#+end_src
|
||||
And same but jumping between frames
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "ace-window"
|
||||
:ensure t
|
||||
:bind("M-l" . 'ace-window)
|
||||
:bind("M-o" . 'ace-delete-window))
|
||||
;; Gotta remove the bad habits
|
||||
(global-unset-key (kbd "C-x o"))
|
||||
#+end_src
|
||||
|
||||
** Expand region
|
||||
#+begin_src emacs-lisp
|
||||
(use-package expand-region
|
||||
:ensure t
|
||||
:init(global-unset-key (kbd "C-q"))
|
||||
(global-set-key (kbd"C-q") 'er/expand-region))
|
||||
|
||||
(defun sosa/mark-words-between-quotes ()
|
||||
"Does that."
|
||||
(interactive)
|
||||
(er/expand-region 2))
|
||||
|
||||
(global-set-key (kbd "C-c q") 'sosa/mark-words-between-quotes)
|
||||
#+end_src
|
||||
** Beacon mode
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "beacon"
|
||||
:ensure t
|
||||
:init(beacon-mode 1))
|
||||
#+end_src
|
||||
** LSP
|
||||
Le language server
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "lsp-mode"
|
||||
:ensure t)
|
||||
#+end_src
|
||||
** Hooks
|
||||
I am tired of =M-x auto-fill-mode= in some modes
|
||||
#+begin_src emacs-lisp
|
||||
(add-hook 'org-mode-hook 'auto-fill-mode)
|
||||
(add-hook 'text-mode-hook 'auto-fill-mode)
|
||||
(add-hook 'sgml-mode-hook 'auto-fill-mode)
|
||||
(add-hook 'sgml-mode-hook 'zencoding-mode)
|
||||
(add-hook 'Man-mode-hook 'sosa/no-lines)
|
||||
(add-hook 'speedbar-mode-hook 'sosa/no-lines)
|
||||
#+end_src
|
||||
** Hungry delete
|
||||
Having to delete multiple whitespaces is one of the things I hate,
|
||||
thankfully there's this thing.
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "hungry-delete"
|
||||
:ensure t
|
||||
:init(global-hungry-delete-mode))
|
||||
#+end_src
|
||||
** Yasnippet
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "yasnippet"
|
||||
:ensure t
|
||||
:config
|
||||
(use-package "yasnippet-snippets"
|
||||
:ensure t)
|
||||
:init(yas-global-mode)
|
||||
(yas-reload-all))
|
||||
#+end_src
|
||||
** Org-mode customization
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "org-bullets"
|
||||
:ensure t
|
||||
:config
|
||||
(add-hook 'org-mode-hook 'org-bullets-mode))
|
||||
(local-unset-key (kbd"C-c C-q"))
|
||||
(set-face-font 'org-level-1 "IBM Plex Mono 16")
|
||||
(set-face-font 'org-level-2 "IBM Plex Mono 15")
|
||||
(set-face-font 'org-level-3 "IBM Plex Mono 14")
|
||||
(set-face-font 'org-level-4 "IBM Plex Mono 14")
|
||||
(set-face-font 'org-level-5 "IBM Plex Mono 14")
|
||||
(setq org-hide-emphasis-markers t)
|
||||
#+end_src
|
||||
** zzz-to-char
|
||||
It's like ace-whatever but for zapping characters.
|
||||
=zap-to-char=
|
||||
#+begin_src emacs-lisp
|
||||
(use-package zzz-to-char
|
||||
:ensure t
|
||||
:bind("M-z" . 'zzz-up-to-char))
|
||||
#+end_src
|
||||
** Helpful
|
||||
Better \*help\* buffer
|
||||
#+begin_src emacs-lisp
|
||||
(use-package helpful
|
||||
:ensure t
|
||||
:bind ("C-h f". #'helpful-callable)
|
||||
:bind ("C-h v". #'helpful-variable)
|
||||
:bind ("C-h k". #'helpful-key))
|
||||
|
||||
#+end_src
|
||||
** Projectile
|
||||
Projectile is a project manager which helps you with git and stuff.
|
||||
#+begin_src emacs-lisp
|
||||
(use-package projectile
|
||||
:ensure t
|
||||
:init(projectile-mode))
|
||||
|
||||
#+end_src
|
||||
** Ack
|
||||
Ack is a replacement for =grep(1)= written in Perl, it's fast and
|
||||
stuff. And has support for Perl regular expressions. Because it is
|
||||
written in Perl.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "ack"
|
||||
:ensure t)
|
||||
#+end_src
|
||||
** whitespace-cleanup-mode
|
||||
Useful for makefiles.
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "whitespace-cleanup-mode"
|
||||
:ensure t
|
||||
:init(add-hook 'after-init-hook 'whitespace-cleanup-mode))
|
||||
#+end_src
|
||||
** Nyancat
|
||||
Yes.
|
||||
#+begin_src emacs-lisp
|
||||
(use-package nyan-mode
|
||||
:ensure t
|
||||
:init(nyan-mode))
|
||||
|
||||
#+end_src
|
||||
<<<<<<< HEAD
|
||||
** Orderless
|
||||
#+begin_src emacs-lisp
|
||||
(use-package orderless
|
||||
:ensure t
|
||||
:custom
|
||||
(completion-styles '(orderless basic))
|
||||
(completion-category-overrides '((file (styles basic partial-completion)))))
|
||||
#+end_src
|
||||
** web-mode
|
||||
#+begin_src emacs-lisp
|
||||
(use-package web-mode
|
||||
:ensure t
|
||||
:config
|
||||
(define-key web-mode-map (kbd "C-c C-e") 'web-mode-element-close)
|
||||
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
|
||||
(define-key web-mode-map (kbd "C-c C-o") 'web-mode-element-insert))
|
||||
#+end_src
|
||||
||||||| parent of 5575988 (no se ni que he hecho)
|
||||
|
||||
=======
|
||||
** Orderless
|
||||
#+begin_src emacs-lisp
|
||||
(use-package orderless
|
||||
:ensure t
|
||||
:custom
|
||||
(completion-styles '(orderless basic))
|
||||
(completion-category-overrides '((file (styles basic partial-completion)))))
|
||||
#+end_src
|
||||
** web-mode
|
||||
#+begin_src emacs-lisp
|
||||
(use-package web-mode
|
||||
:ensure t
|
||||
:config
|
||||
(define-key web-mode-map (kbd "C-c C-e") 'web-mode-element-close)
|
||||
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
|
||||
(define-key web-mode-map (kbd "C-c C-o") 'web-mode-element-insert))
|
||||
#+end_src
|
||||
|
||||
>>>>>>> 5575988 (no se ni que he hecho)
|
||||
* Vertico
|
||||
Better interactive selection minibuffer. Alternative to ido and
|
||||
helm. This also installs =marginalia-mode=. So you can have further
|
||||
information of the commands, files and stuff in the minibuffer.
|
||||
#+begin_src emacs-lisp
|
||||
(use-package marginalia
|
||||
:ensure t)
|
||||
|
||||
(use-package vertico
|
||||
|
||||
:ensure t
|
||||
:init
|
||||
(vertico-mode)
|
||||
(marginalia-mode)
|
||||
|
||||
;; Different scroll margin
|
||||
(setq vertico-scroll-margin 10)
|
||||
;; Show more candidates
|
||||
(setq vertico-count 10)
|
||||
;; Grow and shrink the Vertico minibuffer
|
||||
(setq vertico-resize nil)
|
||||
;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
|
||||
(setq vertico-cycle nil))
|
||||
;; Persist history over Emacs restarts. Vertico sorts by history position.
|
||||
(use-package savehist
|
||||
:init
|
||||
(savehist-mode))
|
||||
|
||||
;; A few more useful configurations
|
||||
(use-package emacs
|
||||
:ensure t
|
||||
:init
|
||||
;; Add prompt indicator to `completing-read-multiple'.
|
||||
;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
|
||||
(defun crm-indicator (args)
|
||||
(cons (format "[CRM%s] %s"
|
||||
(replace-regexp-in-string
|
||||
"\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
|
||||
crm-separator)
|
||||
(car args))
|
||||
(cdr args)))
|
||||
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
|
||||
|
||||
;; Do not allow the cursor in the minibuffer prompt
|
||||
(setq minibuffer-prompt-properties
|
||||
'(read-only t cursor-intangible t face minibuffer-prompt))
|
||||
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
|
||||
|
||||
;; Emacs 28: Hide commands in M-x which do not work in the current mode.
|
||||
;; Vertico commands are hidden in normal buffers.
|
||||
;; (setq read-extended-command-predicate
|
||||
;; #'command-completion-default-include-p)
|
||||
|
||||
;; Enable recursive minibuffers
|
||||
(setq enable-recursive-minibuffers t))
|
||||
(advice-add #'vertico--format-candidate :around
|
||||
(lambda (orig cand prefix suffix index _start)
|
||||
(setq cand (funcall orig cand prefix suffix index _start))
|
||||
(concat
|
||||
(if (= vertico--index index)
|
||||
(propertize "-> " 'face 'vertico-current)
|
||||
" ")
|
||||
cand)))
|
||||
(defun vertico-resize--minibuffer ()
|
||||
(add-hook 'window-size-change-functions
|
||||
(lambda (win)
|
||||
(let ((height (window-height win)))
|
||||
(when (/= (1- height) vertico-count)
|
||||
(setq-local vertico-count (1- height))
|
||||
(vertico--exhibit))))
|
||||
t t))
|
||||
|
||||
(advice-add #'vertico--setup :before #'vertico-resize--minibuffer)
|
||||
|
||||
#+end_src
|
||||
|
||||
* CRUX
|
||||
This thing add sane shortcuts for emacs
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "crux"
|
||||
:ensure t
|
||||
:bind("C-k" . 'crux-smart-kill-line)
|
||||
:bind("C-c o" . 'crux-open-with)
|
||||
:bind("C-c D" . 'crux-delete-buffer-and-file)
|
||||
:bind("C-x C-r" . 'crux-reopen-as-root)
|
||||
:bind("C-x C-d" . 'crux-duplicate-current-line-or-region)
|
||||
:bind("C-c u" . 'crux-view-url)
|
||||
:bind("C-c s" . 'crux-create-scratch-buffer))
|
||||
#+end_src
|
||||
* Dashboard
|
||||
The dashboard is a good index for your things. So it's useful to have
|
||||
it
|
||||
|
||||
Here is an useful function I wrote so you can go to the dashboard (Or
|
||||
create it in case you accidentally killed the buffer)
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(global-set-key (kbd "C-c C-d") 'sosa/goto-dashboard)
|
||||
#+end_src
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package dashboard
|
||||
:ensure t
|
||||
:init
|
||||
(dashboard-setup-startup-hook)
|
||||
(setq dashboard-items '(
|
||||
(recents . 7)
|
||||
(bookmarks . 7)
|
||||
))
|
||||
(setq dashboard-startup-banner 'logo)
|
||||
(setq dashboard-banner-logo-title "Welcome to Editor MACroS")
|
||||
(setq dashboard-startup-banner "~/.emacs.d/img/banner.png")
|
||||
(setq dashboard-set-heading-icons t)
|
||||
(setq dashboard-set-file-icons t))
|
||||
#+END_SRC
|
||||
|
||||
* Modeline
|
||||
#+begin_src emacs-lisp
|
||||
(use-package "doom-modeline"
|
||||
:ensure t
|
||||
:init(doom-modeline-mode)
|
||||
:config
|
||||
(setq doom-modeline-height 25)
|
||||
(setq doom-modeline-hud nil)
|
||||
(setq doom-modeline-icon t)
|
||||
(setq doom-modeline-major-mode-icon nil)
|
||||
(setq doom-modeline-time-icon nil)
|
||||
(setq doom-modeline-env-version t)
|
||||
(setq doom-modeline-env-python-executable "python")
|
||||
(setq doom-modeline-env-perl-executable "perl"))
|
||||
|
||||
#+end_src
|
||||
|
||||
|
||||
|
1
init.el
1
init.el
|
@ -1 +0,0 @@
|
|||
(org-babel-load-file "~/.config/emacs/config.org")
|
251
perltidy.el
251
perltidy.el
|
@ -1,251 +0,0 @@
|
|||
;;; perltidy.el --- Tidy perl code
|
||||
|
||||
;; Copyright (C) 2007-2015 Free Software Foundation, Inc.
|
||||
;;
|
||||
;; Author: Ye Wenbin <wenbinye@gmail.com>
|
||||
;; Maintainer: Kirill Babikhin <mrakobes86reg@yandex.ru>
|
||||
;; Created: 22 Dec 2007
|
||||
;; Version: 0.05
|
||||
;; Keywords: tools, convenience, languages
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation; either version 2, or (at your option)
|
||||
;; any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program; if not, write to the Free Software
|
||||
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; As the PBP(Perl Best Practice) suggest, put this to your ~/.perltidyrc:
|
||||
;; ## .perltidyrc --- configuration for perltidy
|
||||
;; # Max line width is 78 cols
|
||||
;; -l=78
|
||||
;; # Indent level is 4 cols
|
||||
;; -i=4
|
||||
;; # Continuation indent is 4 cols
|
||||
;; -ci=4
|
||||
;; # Output to STDOUT
|
||||
;; -st
|
||||
;; # Errors to STDERR
|
||||
;; -se
|
||||
;; # Maximal vertical tightness
|
||||
;; -vt=2
|
||||
;; # No extra indentation for closing brackets
|
||||
;; -cti=0
|
||||
;; # Medium parenthesis tightness
|
||||
;; -pt=1
|
||||
;; # Medium brace tightness
|
||||
;; -bt=1
|
||||
;; # Medium square bracket tightness
|
||||
;; -sbt=1
|
||||
;; # Medium block brace tightness
|
||||
;; -bbt=1
|
||||
;; # No space before semicolons
|
||||
;; -nsfs
|
||||
;; # Don't outdent long quoted strings
|
||||
;; -nolq
|
||||
;; # Break before all operators
|
||||
;; -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
|
||||
|
||||
;; Put this file into your load-path and the following into your ~/.emacs:
|
||||
;; (require 'perltidy)
|
||||
|
||||
;;; Code:
|
||||
|
||||
(eval-when-compile
|
||||
(require 'cl))
|
||||
|
||||
(defgroup perltidy nil
|
||||
"Tidy perl code using perltidy"
|
||||
:group 'tools
|
||||
:group 'pde)
|
||||
|
||||
(defcustom perltidy-program "perltidy"
|
||||
"*Program name of perltidy"
|
||||
:type 'string
|
||||
:group 'perltidy)
|
||||
|
||||
(defcustom perltidy-program-params
|
||||
'(;; I/O control
|
||||
"--standard-output"
|
||||
"--standard-error-output"
|
||||
"--force-read-binary"
|
||||
"--quiet"
|
||||
|
||||
;; FORMATTING OPTIONS
|
||||
"--no-check-syntax"
|
||||
)
|
||||
"*perltidy run options"
|
||||
:type 'list
|
||||
:group 'perltidy)
|
||||
|
||||
(defcustom perltidy-rcregex "\\.perltidyrc"
|
||||
"perltidyrc file regex"
|
||||
:type 'string
|
||||
:group 'perltidy)
|
||||
|
||||
(defmacro perltidy-save-point (&rest body)
|
||||
(declare (indent 0) (debug t))
|
||||
`(let ((old-point (point)))
|
||||
,@body
|
||||
(goto-char old-point)))
|
||||
|
||||
;;;###autoload
|
||||
(defun perltidy-region (beg end)
|
||||
"Tidy perl code in the region."
|
||||
(interactive "r")
|
||||
(or (get 'perltidy-program 'has-perltidy)
|
||||
(if (executable-find perltidy-program)
|
||||
(put 'perltidy-program 'has-perltidy t)
|
||||
(error "Seem perltidy is not installed")))
|
||||
(perltidy-save-point
|
||||
|
||||
(let ((old-perltidy-env (getenv "PERLTIDY"))
|
||||
(remote? (tramp-tramp-file-p buffer-file-name))
|
||||
(perltidyrc (perltidy-find-perltidyrc buffer-file-truename))
|
||||
(perltidyrc-remote (expand-file-name "perltidyrc-remote" temporary-file-directory))
|
||||
(perltidy-run-list perltidy-program-params)
|
||||
)
|
||||
|
||||
(if (and (bound-and-true-p remote?)
|
||||
perltidyrc)
|
||||
(progn
|
||||
(require 'tramp-sh)
|
||||
(tramp-sh-handle-copy-file perltidyrc perltidyrc-remote t)
|
||||
(setq perltidyrc perltidyrc-remote)))
|
||||
|
||||
(if perltidyrc
|
||||
(setq perltidy-run-list
|
||||
(append perltidy-run-list
|
||||
(list (concat "-pro=" perltidyrc)))))
|
||||
|
||||
(apply #'call-process-region
|
||||
(append (list beg end perltidy-program
|
||||
t
|
||||
t
|
||||
t
|
||||
)
|
||||
perltidy-run-list)))
|
||||
t))
|
||||
|
||||
;;;###autoload
|
||||
(defun perltidy-buffer ()
|
||||
"Call perltidy for whole buffer."
|
||||
(interactive)
|
||||
(perltidy-region (point-min) (point-max)))
|
||||
|
||||
;;;###autoload
|
||||
(defun perltidy-subroutine ()
|
||||
"Call perltidy for subroutine at point."
|
||||
(interactive)
|
||||
|
||||
(save-excursion
|
||||
(let ((current-point (point))
|
||||
b e)
|
||||
(setq b (progn (beginning-of-defun) (point)))
|
||||
(when (and
|
||||
(looking-at "\\s-*sub\\s-+")
|
||||
(< b current-point)
|
||||
(> (save-excursion
|
||||
(setq e (progn (end-of-defun) (point))))
|
||||
current-point))
|
||||
(perltidy-region b e)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun perltidy-dwim-safe (arg)
|
||||
"Perltidy Do What I Mean safe.
|
||||
If region is active call perltidy on the region.
|
||||
If inside subroutine, call perltidy on the subroutine,
|
||||
otherwise stop."
|
||||
(interactive "P")
|
||||
(let ((buf (current-buffer))
|
||||
beg end)
|
||||
(cond ((and mark-active transient-mark-mode)
|
||||
(setq beg (region-beginning)
|
||||
end (region-end)))
|
||||
((save-excursion
|
||||
(let ((current-point (point))
|
||||
b e)
|
||||
(setq b (progn (beginning-of-defun) (point)))
|
||||
(when (and
|
||||
(looking-at "\\s-*sub\\s-+")
|
||||
(< b current-point)
|
||||
(> (save-excursion
|
||||
(setq e (progn (end-of-defun) (point))))
|
||||
current-point))
|
||||
(setq beg b
|
||||
end e)))))
|
||||
(t (setq beg nil
|
||||
end nil)))
|
||||
(if (and beg
|
||||
end)
|
||||
(progn
|
||||
(perltidy-region beg end)
|
||||
(font-lock-fontify-buffer)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun perltidy-dwim (arg)
|
||||
"Perltidy Do What I Mean.
|
||||
If region is active call perltidy on the region.
|
||||
If inside subroutine, call perltidy on the subroutine,
|
||||
otherwise call perltidy for whole buffer."
|
||||
(interactive "P")
|
||||
(let ((buf (current-buffer))
|
||||
beg end)
|
||||
(cond ((and mark-active transient-mark-mode)
|
||||
(setq beg (region-beginning)
|
||||
end (region-end)))
|
||||
((save-excursion
|
||||
(let ((current-point (point))
|
||||
b e)
|
||||
(setq b (progn (beginning-of-defun) (point)))
|
||||
(when (and
|
||||
(looking-at "\\s-*sub\\s-+")
|
||||
(< b current-point)
|
||||
(> (save-excursion
|
||||
(setq e (progn (end-of-defun) (point))))
|
||||
current-point))
|
||||
(setq beg b
|
||||
end e)))))
|
||||
(t (setq beg (point-min)
|
||||
end (point-max))))
|
||||
(perltidy-region beg end)
|
||||
(font-lock-fontify-buffer)))
|
||||
|
||||
(defun perltidy-find-perltidyrc (&optional dir rcregex)
|
||||
(unless dir (setq dir (buffer-file-name)))
|
||||
(unless rcregex (setq rcregex perltidy-rcregex))
|
||||
(setq dir (file-name-directory dir))
|
||||
|
||||
(let (rcfile)
|
||||
(catch 'my-tag
|
||||
(locate-dominating-file
|
||||
dir
|
||||
(lambda (parent)
|
||||
(let ((rc (car (ignore-errors (directory-files parent t rcregex))))
|
||||
(pparent (file-name-directory (directory-file-name parent))))
|
||||
(setq rcfile rc)
|
||||
(cond ((equal parent
|
||||
pparent)
|
||||
(if (= (length rc) 0)
|
||||
(throw 'my-tag rc)
|
||||
(throw 'my-tag nil)))
|
||||
|
||||
((and (= (length rc) 0)
|
||||
(file-exists-p (expand-file-name "lib" pparent))
|
||||
(file-directory-p (expand-file-name "lib" pparent)))
|
||||
(setq rcfile (car (ignore-errors (directory-files pparent t rcregex))))
|
||||
(throw 'my-tag rcfile))
|
||||
(t rc))))))
|
||||
rcfile))
|
||||
|
||||
(provide 'perltidy)
|
||||
;;; perltidy.el ends here
|
|
@ -1 +0,0 @@
|
|||
config.org
|
166
src/.clang-format
Normal file
166
src/.clang-format
Normal file
|
@ -0,0 +1,166 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Mozilla
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: None
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: TopLevel
|
||||
AlwaysBreakAfterReturnType: TopLevel
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeBraces: Mozilla
|
||||
BreakBeforeInheritanceComma: true
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 5
|
||||
ContinuationIndentWidth: 5
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: true
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentRequires: false
|
||||
IndentWidth: 5
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: None
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 5
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
PenaltyBreakAssignment: 5
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: false
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
BitFieldColonSpacing: Both
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 5
|
||||
UseCRLF: false
|
||||
UseTab: Always
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
- NS_SWIFT_NAME
|
||||
- CF_SWIFT_NAME
|
||||
...
|
||||
|
53
src/Makefile
Normal file
53
src/Makefile
Normal file
|
@ -0,0 +1,53 @@
|
|||
# This makefile is BSD compatiable: You can run it without gmake on most systems
|
||||
|
||||
CC = cc
|
||||
PREFIX = /usr/local
|
||||
|
||||
compile:
|
||||
mkdir -p bin
|
||||
$(CC) -c *.c nouserland/*.c
|
||||
$(CC) -o bin/cat cat.o
|
||||
$(CC) -o bin/chmod chmod.o
|
||||
$(CC) -o bin/chown chown.o
|
||||
$(CC) -o bin/cp cp.o
|
||||
$(CC) -o bin/dirname dirname.o
|
||||
$(CC) -o bin/echo echo.o
|
||||
$(CC) -o bin/exec exec.o
|
||||
$(CC) -o bin/false false.o
|
||||
$(CC) -o bin/groups groups.o
|
||||
$(CC) -o bin/head head.o
|
||||
$(CC) -o bin/hostid hostid.o
|
||||
$(CC) -o bin/hostname hostname.o
|
||||
$(CC) -o bin/id id.o
|
||||
$(CC) -o bin/kill kill.o
|
||||
$(CC) -o bin/ln ln.o
|
||||
$(CC) -o bin/longname logname.o
|
||||
$(CC) -o bin/ls ls.o
|
||||
$(CC) -o bin/mkdir mkdir.o
|
||||
$(CC) -o bin/mount mount.o
|
||||
$(CC) -o bin/mv mv.o
|
||||
$(CC) -o bin/nproc nproc.o
|
||||
$(CC) -o bin/pwd pwd.o
|
||||
$(CC) -o bin/rm rm.o
|
||||
$(CC) -o bin/rmdir rmdir.o
|
||||
$(CC) -o bin/shred shred.o
|
||||
$(CC) -o bin/sleep sleep.o
|
||||
$(CC) -o bin/sync sync.o
|
||||
$(CC) -o bin/touch touch.o
|
||||
$(CC) -o bin/true true.o
|
||||
$(CC) -o bin/tty tty.o
|
||||
$(CC) -o bin/umount umount.o
|
||||
$(CC) -o bin/unlink unlink.o
|
||||
$(CC) -o bin/wc wc.o
|
||||
$(CC) -o bin/whoami whoami.o
|
||||
$(CC) -o bin/yes yes.o
|
||||
$(CC) -o bin/uname uname.o
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -fr bin/
|
||||
install:
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/k9core
|
||||
cp bin/* /usr/local/k9core/
|
||||
.PHONY:
|
||||
clean objclean compile
|
42
src/cat.c
Normal file
42
src/cat.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
cat(int fd, const char *filename)
|
||||
{
|
||||
int c;
|
||||
char buf[8192];
|
||||
if(filename[0] == '-' && filename[1] != 'u')
|
||||
fd = 0;
|
||||
|
||||
if(fd != 0)
|
||||
fd = open(filename, O_RDONLY);
|
||||
|
||||
if(fd == -1) {
|
||||
fprintf(stderr, "error opening %s: %s\n", filename, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
while((c = read(fd, buf, sizeof(buf))) > 0) {
|
||||
if(c == -1)
|
||||
return -1;
|
||||
write(1, buf, c);
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
getopt(argc, argv, "u");
|
||||
if(argc == optind)
|
||||
cat(0, "-");
|
||||
for(int i = optind; i < argc; i++)
|
||||
cat(1, argv[i]);
|
||||
|
||||
return 0;
|
||||
}
|
33
src/chgrp.c
Normal file
33
src/chgrp.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int follow_symlink;
|
||||
while((c = getopt(argc, argv, "h")) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
follow_symlink = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(argc == 1 || argc == 2) {
|
||||
fprintf(stderr, "usage: chgrp group file...\n");
|
||||
return 1;
|
||||
}
|
||||
struct group *group_data = getgrnam(argv[optind]);
|
||||
gid_t gid = group_data->gr_gid;
|
||||
for(int i = optind + 1; i < argc; i++) {
|
||||
if(follow_symlink) {
|
||||
if(lchown(argv[i], gid, getuid()) == -1)
|
||||
fprintf(stderr, "Error: %i = %s\n", errno, strerror(errno));
|
||||
} else if(chown(argv[i], gid, getuid()) == -1) {
|
||||
fprintf(stderr, "Error: %i = %s\n", errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
22
src/chmod.c
Normal file
22
src/chmod.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
mode_t mode = atoi(argv[1]);
|
||||
for(int i = 2; i < argc; i++) {
|
||||
int fd = chmod(argv[i], mode);
|
||||
if(fd == -1) fprintf(stderr,
|
||||
"Error setting %i on %s\n %i = %s",
|
||||
mode,
|
||||
argv[i],
|
||||
errno,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
26
src/chown.c
Normal file
26
src/chown.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* TODO: use strtok() to get the group */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "No command given\n");
|
||||
return 1;
|
||||
}
|
||||
const char *user = argv[1];
|
||||
|
||||
struct passwd *data = getpwnam(user);
|
||||
uid_t uid = data->pw_gid;
|
||||
gid_t gid = data->pw_gid; /* Change this with the strtok() thing */
|
||||
|
||||
for(int i = 2; i <= argc; i++) {
|
||||
chown(argv[i], uid, gid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
14
src/chroot.c
Normal file
14
src/chroot.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* UNTESTED */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "Missing operand\n");
|
||||
return 1;
|
||||
}
|
||||
chroot(argv[1]);
|
||||
}
|
45
src/cp.c
Normal file
45
src/cp.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
copy(const char *src, const char *dst)
|
||||
{
|
||||
int source = open(src, O_RDONLY);
|
||||
int destination = creat(dst, 0644);
|
||||
|
||||
if(destination == -1) {
|
||||
fprintf(stderr,
|
||||
"Error opening destination file: %i = %s\n",
|
||||
errno,
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
if(source == -1) {
|
||||
fprintf(stderr,
|
||||
"Error opening source file: %i = %s\n",
|
||||
errno,
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
int lines;
|
||||
char buf[8912];
|
||||
while((lines = read(source, buf, sizeof(buf))) > 0)
|
||||
write(destination, buf, lines);
|
||||
close(destination);
|
||||
close(source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "usage: cp source destination\n");
|
||||
return 1;
|
||||
} else
|
||||
fd = copy(argv[1], argv[2]);
|
||||
}
|
39
src/date.c
Normal file
39
src/date.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int u = 0;
|
||||
char buffer[256];
|
||||
time_t now;
|
||||
now = time(NULL);
|
||||
char FORMAT[256] = "%c";
|
||||
struct tm *timeinfo;
|
||||
|
||||
while((c = getopt(argc, argv, "u")) != -1) {
|
||||
switch(c) {
|
||||
case 'u':
|
||||
u = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
timeinfo = localtime(&now);
|
||||
|
||||
if(u)
|
||||
timeinfo = gmtime(&now);
|
||||
|
||||
if(argc > optind && argv[optind][0] == '+') {
|
||||
argv[optind]++;
|
||||
strcpy(FORMAT, argv[optind]);
|
||||
}
|
||||
|
||||
strftime(buffer, 256, FORMAT, timeinfo);
|
||||
puts(buffer);
|
||||
return 0;
|
||||
}
|
14
src/dirname.c
Normal file
14
src/dirname.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *dir = dirname(argv[1]);
|
||||
if(dir == NULL) {
|
||||
fprintf(stderr, "%s", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
printf("%s/\n", dir); /* Trailing slash because POSIX */
|
||||
return 0;
|
||||
}
|
32
src/du.c
Normal file
32
src/du.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int human_readable = 0;
|
||||
struct stat file_data;
|
||||
|
||||
while((c = getopt(argc, argv, "h")) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
human_readable = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(argc == optind) {
|
||||
printf("no!\n");
|
||||
return 1;
|
||||
}
|
||||
for(int i = optind; i < argc; i++) {
|
||||
stat(argv[i], &file_data);
|
||||
if(human_readable)
|
||||
printf("%li\t %s", file_data.st_size * 1024, argv[i]);
|
||||
else
|
||||
printf("%li\t %s", file_data.st_size, argv[i]);
|
||||
puts("");
|
||||
}
|
||||
return 0;
|
||||
}
|
22
src/echo.c
Normal file
22
src/echo.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int nflag;
|
||||
if(!strcmp(*++argv, "-n")) {
|
||||
nflag = 1;
|
||||
argv++;
|
||||
}
|
||||
|
||||
while(*argv) {
|
||||
(void)fputs(*argv, stdout); /* Print argv */
|
||||
if(*++argv)
|
||||
putchar(' '); /* If multiple things in argv, print a space
|
||||
between them. */
|
||||
}
|
||||
if(!nflag)
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
14
src/exec.c
Normal file
14
src/exec.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "what do you want to do?\n");
|
||||
return 1;
|
||||
}
|
||||
char *const argv2[1] = { argv[2] };
|
||||
execv(argv[1], argv2);
|
||||
return 0;
|
||||
}
|
5
src/false.c
Normal file
5
src/false.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
int
|
||||
main(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
26
src/groups.c
Normal file
26
src/groups.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct passwd *pwd;
|
||||
if(argc == 2)
|
||||
pwd = getpwnam(argv[1]);
|
||||
else
|
||||
pwd = getpwuid(getuid());
|
||||
|
||||
int ngroups = 10;
|
||||
uid_t *groups = malloc(ngroups);
|
||||
getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ngroups);
|
||||
struct group *gr;
|
||||
for(int i = 0; i < ngroups; i++) {
|
||||
gr = getgrgid(groups[i]);
|
||||
printf("%s ", gr->gr_name);
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
49
src/head.c
Normal file
49
src/head.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
head(FILE *file, int lines)
|
||||
{
|
||||
if(file == NULL) {
|
||||
fprintf(
|
||||
stderr, "error opening file: %i = %s\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
int a;
|
||||
int c = 0;
|
||||
|
||||
while((a = fgetc(file)) != EOF) {
|
||||
if(a == '\n')
|
||||
++c;
|
||||
|
||||
putchar(a);
|
||||
if(c == lines)
|
||||
return lines;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int lines = 10;
|
||||
switch(argc) {
|
||||
case 1:
|
||||
head(stdin, lines);
|
||||
break;
|
||||
case 2:
|
||||
head(fopen(argv[1], "r"), lines);
|
||||
break;
|
||||
case 3:
|
||||
lines = abs(atoi(argv[1]));
|
||||
head(fopen(argv[2], "r"), lines);
|
||||
break;
|
||||
default:
|
||||
lines = atoi(argv[2]);
|
||||
head(fopen(argv[3], "r"), lines);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
11
src/hostid.c
Normal file
11
src/hostid.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
long id = gethostid();
|
||||
printf("%lx\n", id);
|
||||
|
||||
return 0;
|
||||
}
|
11
src/hostname.c
Normal file
11
src/hostname.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char buf[64];
|
||||
gethostname(buf, 64);
|
||||
puts(buf);
|
||||
return 0;
|
||||
}
|
27
src/id.c
Normal file
27
src/id.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <getopt.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c = getopt(argc, argv, "Ggnru");
|
||||
struct passwd *user_data = getpwnam(getlogin());
|
||||
switch(c) {
|
||||
case 'g':
|
||||
case 'u':
|
||||
printf("%u\n", user_data->pw_gid);
|
||||
break;
|
||||
case 'n':
|
||||
printf("%s\n", user_data->pw_name);
|
||||
break;
|
||||
default:
|
||||
printf("%u %s\n",
|
||||
user_data->pw_gid,
|
||||
user_data->pw_name); /* I know
|
||||
* it does not work
|
||||
* like this */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
63
src/kill.c
Normal file
63
src/kill.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void
|
||||
list_signals(void)
|
||||
{
|
||||
puts("1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) "
|
||||
"SIGTRAP");
|
||||
puts("6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) "
|
||||
"SIGUSR1");
|
||||
puts("11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) "
|
||||
"SIGTERM");
|
||||
puts("16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) "
|
||||
"SIGTSTP");
|
||||
puts("21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) "
|
||||
"SIGXFSZ");
|
||||
puts("26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR");
|
||||
puts("31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) "
|
||||
"SIGRTMIN+3");
|
||||
puts("38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) "
|
||||
"SIGRTMIN+8");
|
||||
puts("43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) "
|
||||
"SIGRTMIN+12 47) SIGRTMIN+13");
|
||||
puts("48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) "
|
||||
"SIGRTMAX-13 52) SIGRTMAX-12");
|
||||
puts("53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) "
|
||||
"SIGRTMAX-8 57) SIGRTMAX-7");
|
||||
puts("58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) "
|
||||
"SIGRTMAX-2");
|
||||
puts("63) SIGRTMAX-1 64) SIGRTMAX");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int sig = 0;
|
||||
pid_t pid;
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "expected something\n");
|
||||
return 1;
|
||||
}
|
||||
if(argv[1][1] == 'l') {
|
||||
list_signals();
|
||||
return 0;
|
||||
}
|
||||
switch(argc) {
|
||||
case 2:
|
||||
sig = 15;
|
||||
pid = atoi(argv[1]);
|
||||
break;
|
||||
case 3:
|
||||
sig = abs(atoi(argv[1]));
|
||||
pid = abs(atoi(argv[2]));
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Specify who to kill\n");
|
||||
return 1;
|
||||
}
|
||||
kill(pid, sig);
|
||||
return 0;
|
||||
}
|
48
src/ln.c
Normal file
48
src/ln.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if(argc == 1) {
|
||||
printf("Usage: ln oldfile newfile\n");
|
||||
return 1;
|
||||
}
|
||||
int opts, fd, fflag;
|
||||
while((opts = getopt(argc, argv, "sf")) != -1) {
|
||||
if(opts == 'f')
|
||||
fflag = 1;
|
||||
switch(opts) {
|
||||
case 's':
|
||||
if(fflag == 1 && (access(argv[3], F_OK) != 1)) {
|
||||
if(remove(argv[3]) == -1)
|
||||
rmdir(argv[3]);
|
||||
}
|
||||
int symstat = symlink(argv[2], argv[3]);
|
||||
if(symstat == -1) {
|
||||
fprintf(stderr,
|
||||
"Symlink error: %i = %s",
|
||||
errno,
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
printf("-%c: Argument not found", optopt);
|
||||
break;
|
||||
default:
|
||||
fd = link(argv[1], argv[2]);
|
||||
if(fd == -1) {
|
||||
fprintf(stderr,
|
||||
"Error creating link: %i = %s\n",
|
||||
errno,
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
8
src/logname.c
Normal file
8
src/logname.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("%s\n", getlogin());
|
||||
}
|
86
src/ls.c
Normal file
86
src/ls.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
recursive_list_dirs(const char *directory)
|
||||
{
|
||||
DIR *dir = opendir(directory);
|
||||
if(dir == NULL) {
|
||||
fprintf(stderr, "Error opening directory: %s\n", strerror(errno));
|
||||
puts(directory);
|
||||
return -1;
|
||||
}
|
||||
struct dirent *ent;
|
||||
|
||||
while((ent = readdir(dir)) != NULL) {
|
||||
if(ent->d_type == DT_DIR) {
|
||||
char path[1024];
|
||||
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
||||
continue;
|
||||
snprintf(path, sizeof(path), "%s/%s", directory, ent->d_name);
|
||||
printf("%s/%s\n", path, ent->d_name);
|
||||
recursive_list_dirs(path);
|
||||
} else
|
||||
printf("%s\n", ent->d_name);
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int all, show_slash, show_line, recursive;
|
||||
all = show_slash = show_line = recursive = 0;
|
||||
|
||||
while((c = getopt(argc, argv, "lapR")) != -1) {
|
||||
switch(c) {
|
||||
case 'a':
|
||||
all = 1;
|
||||
break;
|
||||
case 'p':
|
||||
show_slash = 1;
|
||||
break;
|
||||
case 'l':
|
||||
show_line = 1;
|
||||
break;
|
||||
case 'R':
|
||||
recursive = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
char directory[256];
|
||||
if(!argv[optind])
|
||||
strcpy(directory, "./");
|
||||
else
|
||||
strcpy(directory, argv[optind]); /* Very dirty code, i'll fix it
|
||||
* later */
|
||||
DIR *dir = opendir(directory);
|
||||
struct dirent *ent;
|
||||
if(recursive) {
|
||||
recursive_list_dirs(directory);
|
||||
return 0;
|
||||
}
|
||||
if(dir != NULL) {
|
||||
while((ent = readdir(dir)) != NULL) {
|
||||
if(ent->d_name[0] == '.' && !all)
|
||||
continue;
|
||||
if(!show_line) {
|
||||
if(ent->d_type == DT_DIR && show_slash)
|
||||
printf("%s/ ", ent->d_name);
|
||||
else
|
||||
printf("%s ", ent->d_name);
|
||||
} else
|
||||
printf("%s\n", ent->d_name);
|
||||
}
|
||||
}
|
||||
puts("");
|
||||
closedir(dir);
|
||||
|
||||
return 0;
|
||||
}
|
42
src/mkdir.c
Normal file
42
src/mkdir.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c = getopt(argc, argv, "p");
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "specify path(s) to make\n");
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
if(c == 'p')
|
||||
{
|
||||
const char tok[2] = "/";
|
||||
char *token;
|
||||
token = strtok(argv[2],tok);
|
||||
char *directories = argv[2];
|
||||
printf("%s\n",directories);
|
||||
while(token != NULL)
|
||||
{
|
||||
mkdir(token,511);
|
||||
token = strtok(NULL,"/");
|
||||
printf("%s",token);
|
||||
strcat(directories,"/");
|
||||
printf("%s",directories);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
for(int i = 1; i < argc; i++) {
|
||||
|
||||
int fd = mkdir(argv[i], 420);
|
||||
if(fd == -1) {
|
||||
fprintf(stderr, "Error creating dir %s\n", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
38
src/mv.c
Normal file
38
src/mv.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
int
|
||||
move(const char *src, const char *dst)
|
||||
{
|
||||
int source = open(src,O_RDONLY);
|
||||
int destination = creat(dst,0644);
|
||||
|
||||
if(destination == -1)
|
||||
{
|
||||
printf("Error opening destination file\n");
|
||||
return 1;
|
||||
}
|
||||
if(source == -1)
|
||||
{
|
||||
printf("Error opening source file\n");
|
||||
return 1;
|
||||
}
|
||||
int lines;
|
||||
char buf[8912];
|
||||
while((lines = read(source,buf,sizeof(buf))) > 0)
|
||||
write(destination,buf,lines);
|
||||
close(destination); close(source);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "usage: mv source destination\n");
|
||||
return 1;
|
||||
} else
|
||||
rename(argv[1], argv[2]);
|
||||
}
|
45
src/nouserland/mount.c
Normal file
45
src/nouserland/mount.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Do NOT use this unironically for now, this only supports ext4, and
|
||||
* you cannot specify another filesystem unless you change the source
|
||||
* code. */
|
||||
|
||||
/* Update: now this supports filetype with -t flag. But I still don't
|
||||
* recommend it to mounting something that it's not extx
|
||||
*/
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
int c = getopt(argc, argv,"t:");
|
||||
if(argc < 2)
|
||||
{
|
||||
printf("./mount source destination\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(getuid() != 0)
|
||||
{
|
||||
fprintf(stderr,"Only root can run this\n");
|
||||
return 1;
|
||||
}
|
||||
char filesystem[10] = "ext4";
|
||||
int source = 1;
|
||||
int destination = 2;
|
||||
if(c == 't')
|
||||
{
|
||||
strcpy(filesystem,optarg);
|
||||
source++;
|
||||
destination++;
|
||||
}
|
||||
int fd = mount(argv[source],argv[destination],filesystem,0,NULL);
|
||||
if(fd == -1)
|
||||
{
|
||||
fprintf(stderr,"error mounting: %i = %s\n",errno,strerror(errno));
|
||||
}
|
||||
return 0;
|
||||
}
|
28
src/nouserland/umount.c
Normal file
28
src/nouserland/umount.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/mount.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c = getopt(argc, argv, "f");
|
||||
int options = 0; /* No options by default */
|
||||
int destination = 1;
|
||||
if(c == 'f')
|
||||
{
|
||||
options = MNT_FORCE;
|
||||
destination++;
|
||||
}
|
||||
if(argc == 1)
|
||||
{
|
||||
printf("give a directory\n");
|
||||
return 1;
|
||||
}
|
||||
int fd = umount2(argv[destination],options);
|
||||
if(fd == -1)
|
||||
{
|
||||
fprintf(stderr,"error umounting: %i = %s\n",errno,strerror(errno));
|
||||
}
|
||||
}
|
10
src/nproc.c
Normal file
10
src/nproc.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int cores = get_nprocs_conf();
|
||||
printf("%i\n", cores);
|
||||
return 0;
|
||||
}
|
9
src/pwd.c
Normal file
9
src/pwd.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
puts(getcwd(NULL, 0));
|
||||
return 0;
|
||||
}
|
22
src/rm.c
Normal file
22
src/rm.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1) {
|
||||
printf("Specify files to remove.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(int i = 1; i < argc; i++) {
|
||||
int fd = remove(argv[i]);
|
||||
if(fd == -1) {
|
||||
fprintf(stderr,
|
||||
"Error removing file: %i = %s",
|
||||
errno,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
19
src/rmdir.c
Normal file
19
src/rmdir.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
for(int i = 1; i < argc; i++) {
|
||||
if(rmdir(argv[i])) {
|
||||
fprintf(stderr,
|
||||
"rmdir: failed to remove '%s', %s\n",
|
||||
argv[i],
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
38
src/shred.c
Normal file
38
src/shred.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
fill_with_zeroes(const char *filename)
|
||||
{
|
||||
int fd = open(filename, O_WRONLY);
|
||||
if(fd == -1) {
|
||||
printf("Error reading file: %i = %s\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
struct stat stat_struct; /* What name should i use? */
|
||||
stat(filename, &stat_struct);
|
||||
long int bytes_to_write = stat_struct.st_size;
|
||||
char *buf = NULL;
|
||||
|
||||
buf = malloc(bytes_to_write);
|
||||
for(int i = 0; i < bytes_to_write; i++)
|
||||
write(fd, "\0\0\0\0\0", bytes_to_write + 2048);
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c = getopt(argc, argv, "u"); /* TODO: add -f */
|
||||
|
||||
fill_with_zeroes(argv[1]);
|
||||
if(c == 'u')
|
||||
remove(argv[1]);
|
||||
}
|
15
src/sleep.c
Normal file
15
src/sleep.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "missing opperand\n");
|
||||
return 1;
|
||||
}
|
||||
usleep(atof(argv[1]) * 1000000);
|
||||
|
||||
return 0;
|
||||
}
|
60
src/stat.c
Normal file
60
src/stat.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "usage: stat FILE...\n");
|
||||
return 1;
|
||||
}
|
||||
char mod_date[64], acc_date[64], creat_date[64];
|
||||
struct stat file_data;
|
||||
for(int i = 1; i < argc; i++) {
|
||||
if(stat(argv[i], &file_data) == -1) {
|
||||
printf("Cannot stat '%s': %s\n", argv[i], strerror(errno));
|
||||
continue;
|
||||
}
|
||||
/* About file size, location... */
|
||||
printf("File: %s\nSize: %lu\t blocks: %li\t IO Block: %li\nDevice: "
|
||||
"%lu\t",
|
||||
argv[i],
|
||||
file_data.st_size,
|
||||
file_data.st_blocks,
|
||||
file_data.st_blksize,
|
||||
file_data.st_dev);
|
||||
/* File permisions
|
||||
* TODO: Display only the permissions (644) instead of the whole mode
|
||||
* (100644)
|
||||
*/
|
||||
printf("Inode: %u\t Links: %lu\nAccess: %o\tUid: %u\tGid:%u\n",
|
||||
file_data.st_gid,
|
||||
file_data.st_nlink,
|
||||
file_data.st_mode,
|
||||
file_data.st_uid,
|
||||
file_data.st_gid);
|
||||
/* Access, creation and modification date */
|
||||
struct tm *timeinfo;
|
||||
/* Modification time */
|
||||
timeinfo = localtime(&file_data.st_mtim.tv_sec);
|
||||
strftime(mod_date, 64, "%F %H:%M:%S", timeinfo);
|
||||
/* Creation time */
|
||||
|
||||
timeinfo = localtime(&file_data.st_ctim.tv_sec);
|
||||
strftime(creat_date, 64, "%F %H:%M:%S", timeinfo);
|
||||
|
||||
/* Access time */
|
||||
timeinfo = localtime(&file_data.st_atim.tv_sec);
|
||||
strftime(acc_date, 64, "%F %H:%M:%S", timeinfo);
|
||||
|
||||
printf("Access: %s\nModify: %s\nCreation %s\n",
|
||||
acc_date,
|
||||
mod_date,
|
||||
creat_date);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
8
src/sync.c
Normal file
8
src/sync.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
sync();
|
||||
return 0;
|
||||
}
|
62
src/tee.c
Normal file
62
src/tee.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
tee(int fd)
|
||||
{
|
||||
if(fd == -1) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
char buf[8192];
|
||||
int read_bytes = 0;
|
||||
while((read_bytes = read(0, buf, 8192)) > 0) {
|
||||
write(fd, buf, read_bytes);
|
||||
if(fd != 1)
|
||||
write(1, buf, read_bytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int append = 0;
|
||||
int ignore_signt = 0;
|
||||
int fd = 0;
|
||||
int FLAGS = O_WRONLY | O_CREAT; /* yeah, it will overwrite the thing if it
|
||||
* can't read what's in the file, thanks
|
||||
* POSIX! */
|
||||
while((c = getopt(argc, argv, "ai")) != -1) {
|
||||
switch(c) {
|
||||
case 'a':
|
||||
append = 1;
|
||||
break;
|
||||
case 'i':
|
||||
ignore_signt = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(argc == optind) {
|
||||
if(ignore_signt)
|
||||
signal(SIGINT, SIG_IGN);
|
||||
tee(1);
|
||||
} else {
|
||||
if(argv[argc - 1][0] == '-')
|
||||
fd = 1;
|
||||
if(append)
|
||||
FLAGS = O_RDWR | O_APPEND; /* Remember what I said? */
|
||||
|
||||
fd = open(argv[argc - 1], FLAGS);
|
||||
if(ignore_signt)
|
||||
signal(SIGINT, SIG_IGN);
|
||||
if(tee(fd) == 1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
11
src/test.c
Normal file
11
src/test.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int x = 3;
|
||||
if(x == 3) {
|
||||
puts("si");
|
||||
}
|
||||
return x;
|
||||
}
|
27
src/touch.c
Normal file
27
src/touch.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc <= 1) {
|
||||
fprintf(stderr, "Give a file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd = creat(argv[1], 0644);
|
||||
|
||||
if(fd == -1) {
|
||||
fprintf(stderr,
|
||||
"Error creating file: %i = %s\n",
|
||||
errno,
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
5
src/true.c
Normal file
5
src/true.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
int
|
||||
main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
9
src/tty.c
Normal file
9
src/tty.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("%s\n", ttyname(1));
|
||||
return 0;
|
||||
}
|
86
src/uname.c
Normal file
86
src/uname.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
const char *
|
||||
get_operating_system()
|
||||
{
|
||||
#ifdef __gnu_linux__
|
||||
return "GNU/Linux";
|
||||
#endif
|
||||
#ifdef __FreeBSD__
|
||||
return "FreeBSD";
|
||||
#endif
|
||||
#ifdef __OpenBSD__
|
||||
return "OpenBSD";
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
return "Here's a USB stick kid, get a real operating system";
|
||||
#endif
|
||||
return "Unknown operating system";
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int all = 0;
|
||||
int machine = 0;
|
||||
int node_name = 0;
|
||||
int kernel_release = 0;
|
||||
int kernel_name = 0;
|
||||
int operating_system = 0;
|
||||
int nothing = 0;
|
||||
struct utsname kernel_info;
|
||||
|
||||
if(argc == 1)
|
||||
nothing = 1;
|
||||
while((c = getopt(argc, argv, "amnrsv")) != -1) {
|
||||
switch(c) {
|
||||
case 'a':
|
||||
all = 1;
|
||||
break;
|
||||
case 'm':
|
||||
machine = 1;
|
||||
break;
|
||||
case 'n':
|
||||
node_name = 1;
|
||||
break;
|
||||
case 'r':
|
||||
kernel_release = 1;
|
||||
break;
|
||||
case 's':
|
||||
kernel_name = 1;
|
||||
break;
|
||||
case 'v':
|
||||
operating_system = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uname(&kernel_info);
|
||||
|
||||
if(all) {
|
||||
printf("%s %s %s %s %s %s\n",
|
||||
kernel_info.sysname,
|
||||
kernel_info.nodename,
|
||||
kernel_info.release,
|
||||
kernel_info.version,
|
||||
kernel_info.machine,
|
||||
get_operating_system());
|
||||
} else {
|
||||
if(machine)
|
||||
printf("%s ", kernel_info.machine);
|
||||
if(node_name)
|
||||
printf("%s ", kernel_info.nodename);
|
||||
if(kernel_release)
|
||||
printf("%s ", kernel_info.release);
|
||||
if(kernel_name || nothing)
|
||||
printf("%s ", kernel_info.sysname);
|
||||
if(operating_system)
|
||||
printf("%s", get_operating_system());
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
19
src/unlink.c
Normal file
19
src/unlink.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 1) {
|
||||
fprintf(stderr, "What do I unlink?\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd = unlink(argv[1]);
|
||||
if(fd == -1) {
|
||||
fprintf(stderr, "Error unlinking: %i = %s\n", errno, strerror(errno));
|
||||
}
|
||||
return 0;
|
||||
}
|
115
src/wc.c
Normal file
115
src/wc.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int show_lines, show_words, show_bytes;
|
||||
struct wc_values data;
|
||||
|
||||
struct wc_values
|
||||
{
|
||||
int lines;
|
||||
int bytes;
|
||||
int words;
|
||||
int total_lines;
|
||||
int total_bytes;
|
||||
int total_words;
|
||||
};
|
||||
|
||||
int
|
||||
wc(const char *filename, struct wc_values *data)
|
||||
{
|
||||
FILE *file = fopen(filename, "r");
|
||||
if(file == NULL) {
|
||||
fprintf(stderr,
|
||||
"error opening file %s: %s\n",
|
||||
filename,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
size_t c;
|
||||
char buf;
|
||||
int newlines, spaces, bytes = 0;
|
||||
newlines = spaces = bytes = 0;
|
||||
while((c = fread(&buf, 1, 1, file)) > 0) {
|
||||
if(!isascii(buf))
|
||||
buf = toascii(buf);
|
||||
bytes++;
|
||||
if(buf == '\n')
|
||||
newlines++;
|
||||
if(isspace(buf))
|
||||
spaces++;
|
||||
}
|
||||
data->bytes = bytes;
|
||||
data->lines = newlines;
|
||||
data->words = spaces;
|
||||
|
||||
data->total_bytes += data->bytes;
|
||||
data->total_lines += data->lines;
|
||||
data->total_words += data->words;
|
||||
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
print_values(const char *filename, struct wc_values data)
|
||||
{
|
||||
if(show_bytes && show_lines && show_words)
|
||||
printf("%i %i %i", data.lines, data.words, data.bytes);
|
||||
else {
|
||||
if(!show_lines)
|
||||
printf("%i ", data.lines);
|
||||
if(!show_words)
|
||||
printf("%i ", data.words);
|
||||
if(!show_bytes)
|
||||
printf("%i ", data.bytes);
|
||||
}
|
||||
printf(" %s\n", filename);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
struct wc_values data;
|
||||
data.total_bytes = data.total_lines = data.total_words = 0;
|
||||
int return_value = 0; /* Please let me know a better name */
|
||||
show_lines = show_words = show_bytes = 1;
|
||||
/* Process arguments */
|
||||
while((c = getopt(argc, argv, "lwcm")) > 0) {
|
||||
switch(c) {
|
||||
case 'l':
|
||||
show_lines = 0;
|
||||
break;
|
||||
case 'w':
|
||||
show_words = 0;
|
||||
break;
|
||||
case 'c':
|
||||
case 'm':
|
||||
show_bytes = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(optind == argc) {
|
||||
wc("/dev/stdin", &data); /* lol */
|
||||
print_values("stdin", data);
|
||||
} else
|
||||
for(int i = optind; i < argc; i++) {
|
||||
if(argv[i][0] == '-' && argv[i][1] == '\0')
|
||||
return_value = wc("/dev/stdin", &data);
|
||||
else
|
||||
return_value = wc(argv[i], &data);
|
||||
if(return_value == 0)
|
||||
print_values(argv[i], data);
|
||||
}
|
||||
if(argc > optind + 1)
|
||||
printf("%i %i %i total\n",
|
||||
data.total_lines,
|
||||
data.total_words,
|
||||
data.total_bytes);
|
||||
|
||||
return 0;
|
||||
}
|
10
src/whoami.c
Normal file
10
src/whoami.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
struct passwd *user_data = getpwuid(getuid());
|
||||
printf("%s\n", user_data->pw_name);
|
||||
}
|
13
src/yes.c
Normal file
13
src/yes.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if(argc > 1)
|
||||
while(1)
|
||||
puts(argv[1]);
|
||||
else
|
||||
while(1)
|
||||
puts("y");
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue