1
0
mirror of https://github.com/chubin/cheat.sh.git synced 2026-06-20 13:16:44 +02:00

Merge pull request #89 from bglopez/master

Bring up to date with upstream
This commit is contained in:
Igor Chubin
2018-08-12 14:51:26 +02:00
committed by GitHub
13 changed files with 98 additions and 23 deletions
+5
View File
@@ -0,0 +1,5 @@
.travis.yml
.git
.gitignore
docker-compose.yml
Dockerfile
+1
View File
@@ -4,3 +4,4 @@ ve/
share/vim/.vim/
share/vim/.viminfo
typescript
venv/
+24
View File
@@ -0,0 +1,24 @@
dist: trusty
sudo: required
language:
- generic
services:
- docker
env:
DOCKER_COMPOSE_VERSION: 1.22.0
addons:
apt:
packages:
- docker-ce
before_install:
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- docker-compose up -d
- docker ps
+13
View File
@@ -0,0 +1,13 @@
FROM alpine:latest
WORKDIR /app
COPY . /app
RUN apk add --update --no-cache python2 py2-pip py2-gevent \
py2-flask py2-requests py2-pygments py2-redis \
py2-cffi py2-icu bash vim gawk sed \
&& apk add --no-cache --virtual build-deps python2-dev \
build-base git \
&& pip install -r requirements.txt \
&& sh share/scripts/get-sheets.sh \
&& apk del build-deps
ENTRYPOINT ["python2"]
CMD ["bin/srv.py"]
+11
View File
@@ -17,6 +17,8 @@ What features should it have?
Such a thing exists.
[![Build Status](https://travis-ci.org/bglopez/cheat.sh.svg?branch=master)](https://travis-ci.org/bglopez/cheat.sh)
## Features
**cheat.sh**
@@ -43,6 +45,8 @@ Such a thing exists.
* [Client usage](#client-usage)
* [Tab-completion](#tab-completion)
* [Stealth mode](#stealth-mode)
* [Self-Hosting](#self-hosting)
* [Docker](#docker)
* [Editors integration](#editors-integration)
* [Vim](#vim)
* [Emacs](#emacs)
@@ -405,6 +409,13 @@ because you know what happens when you do.
![when you lie in your interview](http://cheat.sh/files/when-you-lie-katze.png)
## Self-Hosting
### Docker
Currently the easiest way to get a self-hosted instance running is by using the docker-compose.yml file provided in the extra/docker folder.
This pulls down the latest image with baked in cheatsheets and starts the app and a Redis instance to back it, making the service available on port 8002 of the local host. This is currently an early implementation and should probably not be used for anything outside of internal/dev/personal use right now.
## Editors integration
You can use *cheat.sh* directly from the editor
+2 -1
View File
@@ -6,8 +6,9 @@ Main server program.
"""
from __future__ import print_function
from gevent.pywsgi import WSGIServer
from gevent.monkey import patch_all
from gevent.pywsgi import WSGIServer
patch_all()
# pylint: disable=wrong-import-position,wrong-import-order
+14
View File
@@ -0,0 +1,14 @@
version: '2'
services:
app:
image: bglopez/cheat.sh
depends_on:
- redis
ports:
- "8002:8002"
redis:
image: redis:4-alpine
volumes:
- redis_data:/data
volumes:
redis_data:
+15
View File
@@ -0,0 +1,15 @@
version: '2'
services:
app:
build:
context: .
depends_on:
- redis
ports:
- "8002:8002"
redis:
image: redis:4-alpine
volumes:
- redis_data:/data
volumes:
redis_data:
+3 -9
View File
@@ -36,10 +36,10 @@ import redis
MYDIR = os.path.abspath(os.path.join(__file__, '..', '..'))
sys.path.append("%s/lib/" % MYDIR)
from languages_data import VIM_NAME
from globals import PATH_VIM_ENVIRONMENT
from globals import PATH_VIM_ENVIRONMENT, REDISHOST
# pylint: enable=wrong-import-position,wrong-import-order
REDIS = redis.StrictRedis(host='localhost', port=6379, db=1)
REDIS = redis.StrictRedis(host=REDISHOST, port=6379, db=1)
FNULL = open(os.devnull, 'w')
TEXT = 0
CODE = 1
@@ -150,14 +150,10 @@ def _classify_lines(lines):
return line_types
def _unindent_code(line, shift=0):
#if line.startswith(' '):
# return line[4:]
if shift == -1 and line != '':
return ' ' + line
if shift > 0:
if line.startswith(' '*shift):
if shift > 0 and line.startswith(' '*shift):
return line[shift:]
return line
@@ -245,8 +241,6 @@ def _beautify(text, filetype, add_comments=False, remove_text=False):
lines = _cleanup_lines(lines)
lines_classes = zip(_classify_lines(lines), lines)
lines_classes = _wrap_lines(lines_classes, unindent_code=unindent_code)
#for x,y in lines_classes:
# print "%s: %s" % (x, y)
if remove_text:
lines = [line[1] for line in lines_classes if line[0] == 1]
+5 -10
View File
@@ -25,13 +25,13 @@ from polyglot.detect.base import UnknownLanguage
import time
import beautifier
from globals import MYDIR, PATH_TLDR_PAGES, PATH_CHEAT_PAGES, PATH_CHEAT_SHEETS, COLOR_STYLES
from globals import MYDIR, PATH_TLDR_PAGES, PATH_CHEAT_PAGES, PATH_CHEAT_SHEETS, COLOR_STYLES, REDISHOST
from adapter_learnxiny import get_learnxiny, get_learnxiny_list, is_valid_learnxy
from languages_data import LANGUAGE_ALIAS, SO_NAME, rewrite_editor_section_name
from colorize_internal import colorize_internal
# pylint: enable=wrong-import-position,wrong-import-order
REDIS = redis.StrictRedis(host='localhost', port=6379, db=0)
REDIS = redis.StrictRedis(host=REDISHOST, port=6379, db=0)
MAX_SEARCH_LEN = 20
@@ -170,13 +170,10 @@ def get_topic_type(topic): # pylint: disable=too-many-locals,too-many-branches,t
if '+' in topic_name:
result = 'question'
else:
#if topic_type in _get_topics_dirs() and topic_name in [':list']:
if topic_name in [':list']:
if (topic_name in [':list']) or (topic_name in [':learn']):
result = "internal"
elif is_valid_learnxy(topic):
result = 'learnxiny'
elif topic_name in [':learn']:
result = "internal"
else:
# let us activate the 'question' feature for all subsections
result = 'question'
@@ -198,7 +195,6 @@ def get_topic_type(topic): # pylint: disable=too-many-locals,too-many-branches,t
TOPIC_TYPE_CACHE[topic] = result
#print topic, " ", result
return result
#
@@ -241,10 +237,10 @@ def _get_tldr(topic):
line = line[2:]
if line.startswith('-'):
line = '# '+line[2:]
elif line == "":
pass
elif not line.startswith(' '):
line = "# "+line
else:
pass
fixed_answer.append(line)
@@ -472,7 +468,6 @@ def get_answer(topic, keyword, options="", request_options=None): # pylint: disa
# if answer was not found in the cache
# try to find it in one of the repositories
if not answer:
#topic_type = get_topic_type(topic)
for topic_getter_type, topic_getter in TOPIC_GETTERS:
if topic_type == topic_getter_type:
+2 -1
View File
@@ -9,6 +9,7 @@ import os
from pygments.styles import get_all_styles
MYDIR = os.path.abspath(os.path.join(__file__, '..', '..'))
REDISHOST = 'redis'
ANSI2HTML = os.path.join(MYDIR, "share/ansi2html.sh")
@@ -18,7 +19,7 @@ TEMPLATES = os.path.join(MYDIR, 'share/templates')
STATIC = os.path.join(MYDIR, 'share/static')
PATH_VIM_ENVIRONMENT = os.path.join(MYDIR, 'share/vim')
USE_OS_PACKAGES = True # change it False if you pull cheat sheets repositories from GitHub
USE_OS_PACKAGES = False # change it False if you pull cheat sheets repositories from GitHub
if USE_OS_PACKAGES:
PATH_TLDR_PAGES = "/home/igor/.tldr/cache/pages/*/*.md"
PATH_CHEAT_PAGES = "/usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/*"
+2 -1
View File
@@ -3,8 +3,9 @@ Support for the stateful queries
"""
import redis
from globals import REDISHOST
REDIS = redis.StrictRedis(host='localhost', port=6379, db=1)
REDIS = redis.StrictRedis(host=REDISHOST, port=6379, db=1)
def save_query(client_id, query):
"""
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
## this doesn't error check, if it breaks and destroys things I'm sorry